byby Audla

  • Integrations
  • Pricing
  • Contact
Sign in
Guides

Developers

Connect your app to Kulanz

@kulanz/connector is the npm package your own apps use to talk to Kulanz from a server. Install it, add one API key, and find, create or update your organization's customers, read their contacts, and list their invoices and quotes.

Create an API key

An admin or owner of the organization creates the key. It opens that organization only, and only for the access you pick.

  1. In Kulanz, switch to the organization the app works for.
  2. Open Organization settings and scroll to API keys.
  3. Give the key a name you will recognise, pick its access, and click Create key.
  4. Copy the key, which starts with kz_live_. Kulanz shows it once and keeps only a fingerprint of it.
AccessLets the app
clients:readRead customers and their contacts
clients:writeCreate and update customers (includes read)
sales:readRead invoices (the organization's or a customer's, with lines) and quotes
sales:writeIssue invoices and quotes from your system, and void invoices (includes sales:read)
payments:readRead payments received
payments:writeRecord and void payments from your system (includes payments:read)

The list shows each key's start, its access, and when it was last used. Revoke stops a key at once. A lost key cannot be shown again: revoke it and create a new one.

Install and set up

The package is public on npm, has no dependencies and runs on Node 18.17 or later, on any server (Next.js server code, Vercel functions, a Node script).

Terminal
pnpm add @kulanz/connector
One setting: store the key as a server secret named KULANZ_API_KEY. The connector calls Kulanz at https://api.kulanz.net by default, so no address is needed.

Create one client in server-only code:

TypeScript
// lib/kulanz.ts
import 'server-only'
import { KulanzClient } from '@kulanz/connector'

export const kulanz = new KulanzClient({
  organization: 'your-org-slug',
  apiKey: process.env.KULANZ_API_KEY!,
})

Methods

These methods cover customers, invoices, quotes and payments. Your system's name for itself (the source) and your own id for a record together identify it in Kulanz.

MethodAccessReturns
clients.findBySource(source, externalId)clients:readThe Kulanz customer, or null if you never created it
clients.upsertFromSource({ source, externalId, name, email?, phone?, contacts? })clients:writeThe customer, and whether this call created it
clients.listContacts(clientExternalId)clients:readThe customer's contacts, default contact first
clients.list({ q?, status?, limit?, offset? })clients:readA page of the organization's customers, sorted by name, with the total count
clients.listInvoices(clientExternalId, { limit?, offset? })sales:readA page of the customer's invoices, newest first, each with its total, payment status and PDF link
clients.listQuotes(clientExternalId, { limit?, offset? })sales:readA page of the customer's quotes, newest first, each with its total, acceptance status and whether it became an invoice
invoices.list({ source?, sourced?, dateFrom?, dateTo?, includeArchived?, q?, limit?, offset? })sales:readA page of the organization's invoices, highest number first; filter by source, by date, or to those no system pushed
invoices.listAll({ …same filters })sales:readEvery invoice matching the same filters, page after page (an async iterator)
invoices.get(ref)sales:readOne invoice with its lines and payments, or null
invoices.findBySource(source, externalId)sales:readThe invoice issued for your sale, or null if none yet
invoices.issueFromSource({ source, externalId, clientSourceId, invoiceDate, lines, … })sales:writeThe invoice Kulanz numbered, taxed and posted, and whether it already existed
invoices.void(ref)sales:writeThe voided invoice; its number is never reused
quotes.upsertFromSource({ source, externalId, clientSourceId, quoteDate, lines, … })sales:writeThe Kulanz copy of your quote, refreshed until it is invoiced
quotes.findBySource(source, externalId)sales:readYour pushed quote with the deposits taken on it, or null
payments.list({ clientExternalId?, dateFrom?, dateTo?, limit?, offset? })payments:readA page of payments received, newest first
payments.recordFromSource({ source, externalId, paymentDate, amount, invoiceRef | quoteExternalId, glCode })payments:writeThe payment, against an invoice or as a deposit on a quote, and whether it already existed
payments.findBySource(source, externalId)payments:readThe payment you recorded, or null
payments.void(paymentId)payments:writeThe voided payment; invoice balances are recomputed
  • Calling the upsert again refreshes the name, email and phone. Terms, notes and contacts stay as your team edited them in Kulanz.
  • Contacts sent with the upsert are added only when that call creates the customer. Each needs a name and an email or phone.
  • Before sending email, keep the contacts that are active and have an email address.

Errors and retries

Each failure is a named error your code can check. None of them contains your API key.

ErrorWhenRetried
KulanzValidationErrorThe request was refused as sent (400 or 422)No
KulanzAuthenticationErrorThe key is unknown, revoked or for another organization (401)No
KulanzPermissionErrorThe key lacks the access this call needs (403)No
KulanzNotFoundErrorThe record does not exist (404)No
KulanzConflictErrorThe call conflicts with the record's state, e.g. voiding an invoice that has payments (409)No
KulanzRateLimitErrorToo many requests (429); Kulanz says when to try againYes
KulanzServerErrorKulanz had a problem (5xx)Yes
KulanzNetworkErrorNo answer: network error or timeoutYes

Only calls that are safe to repeat are retried, a few times with a growing wait: every read, and the writes keyed on your source id (upserts, issue, record, void), which always land on the same record.

Example

Get or create a customer for each of your projects, then collect the email addresses to notify:

TypeScript
import { kulanz } from '@/lib/kulanz'

export async function projectRecipients(project: { id: string; clientName: string; ownerEmail?: string }) {
  // Get or create: safe to call every time.
  const customer = await kulanz.clients.upsertFromSource({
    source: 'my-app',
    externalId: project.id,
    name: project.clientName,
    contacts: project.ownerEmail
      ? [{ name: project.clientName, email: project.ownerEmail, isDefault: true }]
      : undefined,
  })

  const contacts = await kulanz.clients.listContacts(customer.clientExternalId)
  return contacts.filter((c) => c.isActive && c.email).map((c) => c.email!)
}

Keep the key safe

The key opens your organization's customers, so treat it like a password.

  • Keep it in a server secret. Never put it in code, in a public environment variable, or in logs.
  • Use the connector from server code only. It refuses to run in a browser.
  • Give each app its own key, with only the access it needs.
  • To rotate, create a new key, deploy it, then revoke the old one.
  • If a key leaks, revoke it in Organization settings first. It stops working at once.
byby Audla
Product
HomePricingIntegrations
Resources
Knowledge baseGuidesSupport
Company
ContactBrand kit
Legal
PrivacyTerms

Kulanz, a division of Audla Inc.