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.
- In Kulanz, switch to the organization the app works for.
- Open Organization settings and scroll to API keys.
- Give the key a name you will recognise, pick its access, and click Create key.
- Copy the key, which starts with
kz_live_. Kulanz shows it once and keeps only a fingerprint of it.
| Access | Lets the app |
|---|---|
clients:read | Read customers and their contacts |
clients:write | Create and update customers (includes read) |
sales:read | Read invoices (the organization's or a customer's, with lines) and quotes |
sales:write | Issue invoices and quotes from your system, and void invoices (includes sales:read) |
payments:read | Read payments received |
payments:write | Record 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).
pnpm add @kulanz/connectorKULANZ_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:
// 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.
| Method | Access | Returns |
|---|---|---|
clients.findBySource(source, externalId) | clients:read | The Kulanz customer, or null if you never created it |
clients.upsertFromSource({ source, externalId, name, email?, phone?, contacts? }) | clients:write | The customer, and whether this call created it |
clients.listContacts(clientExternalId) | clients:read | The customer's contacts, default contact first |
clients.list({ q?, status?, limit?, offset? }) | clients:read | A page of the organization's customers, sorted by name, with the total count |
clients.listInvoices(clientExternalId, { limit?, offset? }) | sales:read | A page of the customer's invoices, newest first, each with its total, payment status and PDF link |
clients.listQuotes(clientExternalId, { limit?, offset? }) | sales:read | A 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:read | A 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:read | Every invoice matching the same filters, page after page (an async iterator) |
invoices.get(ref) | sales:read | One invoice with its lines and payments, or null |
invoices.findBySource(source, externalId) | sales:read | The invoice issued for your sale, or null if none yet |
invoices.issueFromSource({ source, externalId, clientSourceId, invoiceDate, lines, … }) | sales:write | The invoice Kulanz numbered, taxed and posted, and whether it already existed |
invoices.void(ref) | sales:write | The voided invoice; its number is never reused |
quotes.upsertFromSource({ source, externalId, clientSourceId, quoteDate, lines, … }) | sales:write | The Kulanz copy of your quote, refreshed until it is invoiced |
quotes.findBySource(source, externalId) | sales:read | Your pushed quote with the deposits taken on it, or null |
payments.list({ clientExternalId?, dateFrom?, dateTo?, limit?, offset? }) | payments:read | A page of payments received, newest first |
payments.recordFromSource({ source, externalId, paymentDate, amount, invoiceRef | quoteExternalId, glCode }) | payments:write | The payment, against an invoice or as a deposit on a quote, and whether it already existed |
payments.findBySource(source, externalId) | payments:read | The payment you recorded, or null |
payments.void(paymentId) | payments:write | The 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.
| Error | When | Retried |
|---|---|---|
KulanzValidationError | The request was refused as sent (400 or 422) | No |
KulanzAuthenticationError | The key is unknown, revoked or for another organization (401) | No |
KulanzPermissionError | The key lacks the access this call needs (403) | No |
KulanzNotFoundError | The record does not exist (404) | No |
KulanzConflictError | The call conflicts with the record's state, e.g. voiding an invoice that has payments (409) | No |
KulanzRateLimitError | Too many requests (429); Kulanz says when to try again | Yes |
KulanzServerError | Kulanz had a problem (5xx) | Yes |
KulanzNetworkError | No answer: network error or timeout | Yes |
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:
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.