Skip to main content

Sync contacts and invoices

These endpoints are available in Gäld Community Edition 3.10.0 and later. Use the base URL of the installation running that version.

Use an API token for the organization whose records you are synchronizing. Send it in the Authorization: Bearer header. Paths below are relative to /api/v1. The token needs the contact and invoice permissions for the actions it performs, accounting read access for VAT, and invoice read access for catalogue items. The token's organization determines which records each request can access.

Identify the customer​

Send POST /contacts/upsert with your system name and its stable customer identifier. Store the public contact UUID returned in data.id. The /customers routes address the same contacts.

{
"external_source": "shop",
"external_id": "customer-517",
"name": "Example AG",
"address": "Marktgasse 7",
"postal_code": "3011",
"city": "Bern",
"country": "CH"
}

For an exact lookup, add the top-level query parameters external_source and external_id to the contacts, customers, or invoices collection. References are case-sensitive. A source supports up to 100 characters and an identifier up to 255.

The first successful upsert returns 201. A later update to the same reference returns 200. A 409 on a deleted record means that record still reserves the pair. Keep each pair stable within a resource type and organization. For a network retry of the same mutation, send the same Idempotency-Key and body. Use a new key when you change the request.

Build a draft from catalogue data​

Read GET /invoice-catalog-items and GET /vat-rates. Follow pagination when the record you need is on another page. Both collections also accept a public ID in the detail path. Use the item's default_unit_price and its default_vat_rate_id to construct an invoice line. A VAT rate's public UUID is its id in the VAT response. A catalogue item may have no default VAT rate.

Send the invoice creation fields on every POST /invoices/upsert. To change only a few fields on a known draft, use PATCH /invoices/{invoice}. Replace the two placeholders with the actual UUIDs returned to your integration.

{
"external_source": "shop",
"external_id": "invoice-937",
"customer_id": "<contact UUID>",
"issue_date": "2026-11-23",
"due_date": "2026-12-23",
"currency": "CHF",
"customer_reference": "ACCOUNTS-7",
"purchase_order_reference": "PO-1032",
"delivery_reference": "DEL-88",
"lines": [
{
"description": "Consultation",
"quantity": 1,
"unit_price": "100.00",
"vat_rate_id": "<VAT UUID>"
}
]
}

Use the returned invoice UUID for GET /invoices/{invoice}/pdf. A configured invoicing bank account and valid payment details are required for the Swiss QR invoice. Each supplied commercial reference appears on the customer PDF in the invoice language. External synchronization IDs stay in the API. You can update a reference while the invoice is a draft. Omitting a commercial reference keeps its value, and sending null clears it.

Verify committed invoice events​

Register a public HTTPS endpoint and subscribe to the events your integration needs. Both the web interface and the API emit the following events after the transaction commits.

EventWhen it arrives
invoice.createdA new invoice was created.
invoice.finalizedThe draft was finalized.
invoice.payment_recordedA payment was recorded. Its UUID is included as payment_id.
invoice.cancelledThe invoice was cancelled.

Verify X-Webhook-Signature against the HMAC-SHA256 of the exact request body using your subscription secret. Compare in constant time. Parse JSON only after verification. The payload contains invoice_id, organization_id, event, event_id, and timestamp. Use event_id to recognize a repeat, including deliveries to multiple subscriptions. X-Webhook-Id identifies a delivery to one subscription. Return a successful HTTP response after recording the event. A retry carries the original event and delivery identifiers.

$body = file_get_contents('php://input');
$expected = hash_hmac('sha256', $body, $subscriptionSecret);
if (!hash_equals($expected, $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '')) {
http_response_code(401);
return;
}
$event = json_decode($body, true, flags: JSON_THROW_ON_ERROR);