Skip to content

API and webhooks

The API lets your own systems work with a company in Somdul: an online shop that creates a tax invoice for each order, a POS that records the day’s receipts, or a Zapier, Make or n8n workflow that adds new customers. Webhooks work the other way: Somdul tells your system when something happens, for example when an invoice is paid.

Everything a key does follows the same rules as the app. Documents are numbered the same way, closed months stay closed, and every change is in the audit trail with the key’s name.

Open in Somdul: Settings → API & webhooks

  • Only an Admin of the company can make keys and webhooks.
  • The API and webhooks come with the Business plan and above. In an accounting practice, each client company has its own keys.
  • A key is like a password for the company’s books. Use it only on a server. Never put it in a web page, a phone app or a spreadsheet other people can open.
  • The public demo shows an example key and webhook, but can’t make or use them.
  1. Switch to the company, then open Settings → API & webhooks.

  2. Under API keys, click New key.

  3. Give it a Name that says what uses it, such as “Online shop”.

  4. Tick the Scopes it needs, and nothing more (see the table below).

  5. If you like, set Expires on, and Only from these addresses (your server’s internet address, or a range such as 203.0.113.0/24).

  6. Click Make key. Copy the key that appears and store it safely. It is shown only once: Somdul keeps only a fingerprint of it (a SHA-256 hash), so it can’t show it again.

To stop a key, click Revoke. It stops working at once. A key can’t be edited: revoke it and make a new one.

Area Read Create Post
Customers and suppliers contacts:read contacts:write
Products products:read products:write
Sales documents (tax invoices, quotations, receipts) sales:read sales:write (drafts) sales:post
Supplier bills purchases:read purchases:write (drafts only)
Stock on hand stock:read
Chart of accounts accounts:read

sales:post lets the key post tax invoices and receipts, and issue quotations. Supplier bills always arrive as drafts, so someone checks them against the supplier’s paper before posting.

A key acts as the admin who made it. If that person stops being an admin of the company, the key stops working and needs to be made again by another admin.

The address of the API is:

https://avfzzptywwpwgcugvqyu.supabase.co/functions/v1/api/v1

Send the key in the Authorization header. A quick test that returns the company and the key’s scopes:

Terminal window
curl https://avfzzptywwpwgcugvqyu.supabase.co/functions/v1/api/v1/me \
-H "Authorization: Bearer $SOMDUL_API_KEY"

Every endpoint, field and answer is described in the OpenAPI 3.1 file at my.somdul.app/openapi.json. Tools such as Postman and Insomnia can import it.

Method and path Scope What it does
GET /v1/me any The company and the key
GET /v1/contacts, GET /v1/contacts/{id} contacts:read Customers and suppliers
POST /v1/contacts contacts:write Create a customer or supplier
GET /v1/products, GET /v1/products/{id} products:read Products and services
POST /v1/products products:write Create a product or service
GET /v1/invoices, GET /v1/invoices/{id} sales:read Tax invoices, with payment status
POST /v1/invoices sales:write Create a tax invoice (a draft, or posted with "post": true)
POST /v1/invoices/{id}/post sales:post Post a draft tax invoice
GET /v1/invoices/{id}/payments sales:read The receipts that paid an invoice
GET /v1/quotes, GET /v1/quotes/{id} sales:read Quotations
POST /v1/quotes, POST /v1/quotes/{id}/issue sales:write, sales:post Create or issue a quotation
GET /v1/receipts, GET /v1/receipts/{id} sales:read Receipts
POST /v1/receipts, POST /v1/receipts/{id}/post sales:write, sales:post Record a payment received
GET /v1/bills, GET /v1/bills/{id} purchases:read Supplier bills
POST /v1/bills purchases:write Create a supplier bill (always a draft)
GET /v1/stock stock:read Stock on hand by product and warehouse
GET /v1/accounts accounts:read The chart of accounts

Create a customer, then a posted tax invoice

Section titled “Create a customer, then a posted tax invoice”
Terminal window
curl -X POST https://avfzzptywwpwgcugvqyu.supabase.co/functions/v1/api/v1/contacts \
-H "Authorization: Bearer $SOMDUL_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: customer-8812" \
-d '{"type":"customer","name_th":"บริษัท ตัวอย่างลูกค้า จำกัด","name_en":"Sample Customer Co., Ltd.","tax_id":"0105500000001","credit_days":30}'
curl -X POST https://avfzzptywwpwgcugvqyu.supabase.co/functions/v1/api/v1/invoices \
-H "Authorization: Bearer $SOMDUL_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: order-1001" \
-d '{"contact_id":"<customer id>","date":"2026-11-01","reference":"ORDER-1001","post":true,
"lines":[{"product_id":"<product id>","qty":"2","unit_price":"250.00"}]}'

Without "post": true the invoice is saved as a draft for someone to check and post in Somdul. If posting is refused (for example the month is closed), nothing is created and the answer says why.

Terminal window
curl -X POST https://avfzzptywwpwgcugvqyu.supabase.co/functions/v1/api/v1/receipts \
-H "Authorization: Bearer $SOMDUL_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: payment-psp-889" \
-d '{"contact_id":"<customer id>","date":"2026-11-03","deposit_account_code":"1121","post":true,
"allocations":[{"invoice_id":"<invoice id>","amount":"535.00"}]}'

deposit_account_code is the cash or bank account in your chart of accounts. If the customer withheld tax, send wht_amount and allocate the invoice’s full amount, as in the app.

  • Money is a string with two decimals ("1500.00"), so no amount is ever rounded by a computer’s floating point. Quantities are strings too ("2", "1.5").
  • Dates are YYYY-MM-DD. Times are in UTC, ISO 8601 (2026-11-01T03:15:00Z).
  • Lists are newest first, 50 at a time (up to 200 with limit). When has_more is true, ask again with cursor set to the next_cursor you were given. Filter with status, from, to, contact_id, updated_since (and payment_status for invoices, type and q for contacts).
  • Idempotency-Key: send a unique value (such as your order number) with every create. If the network drops and you send the same request again with the same key within 48 hours, you get the first answer back (header Idempotent-Replayed: true) instead of a second invoice.
  • Limits: 1,200 requests an hour and 20,000 a day per key. Beyond that the answer is 429 with Retry-After.
  • Unknown fields are refused rather than ignored, so a typo shows up straight away.

Errors come back as JSON with an HTTP status and the same error code the app uses:

{ "error": { "code": "ERR_PERIOD_CLOSED", "status": 422, "message": "Refused by a business rule (ERR_PERIOD_CLOSED). …", "request_id": "…" } }
Status Common codes What to do
401 ERR_API_KEY, ERR_API_KEY_REVOKED, ERR_API_KEY_EXPIRED Check the key, or make a new one
403 ERR_API_SCOPE, ERR_API_IP, ERR_PLAN_FEATURE, ERR_API_KEY_OWNER Add the scope (new key), call from an allowed address, check the plan
404 ERR_NOT_FOUND, ERR_API_ROUTE The record isn’t this company’s, or the path is wrong
409 ERR_DOC_LOCKED, ERR_API_DUPLICATE_CODE, ERR_API_IDEMPOTENCY Already posted, the code exists, or the Idempotency-Key was used for something else
422 ERR_API_INVALID (with details naming each field), ERR_PERIOD_CLOSED, ERR_API_CONTACT, ERR_API_PRODUCT, ERR_API_ACCOUNT Fix the request; a business rule refused it
429 ERR_RATE_LIMIT Wait and try again
  1. Open Settings → API & webhooks and, under Webhooks, click Add endpoint.

  2. Enter the Address where your system receives messages. It must start with https:// and be reachable from the internet.

  3. Tick the Events it should hear about, and click Save.

  4. Copy the Signing secret that appears. It is shown once; New secret makes another (the old one stops at once).

  5. Click Send a test. Within a minute a ping message arrives and Latest deliveries shows your server’s answer.

Event Sent when
invoice.posted A tax invoice is posted
invoice.paid A tax invoice is paid in full (by receipts or credit notes)
invoice.cancelled A posted tax invoice is cancelled
receipt.posted A receipt is posted
bill.posted A supplier bill is posted
contact.created A customer or supplier is added
stock.low A product’s stock (all warehouses) falls below its reorder level, at most once a day per product

A message carries ids, document numbers, dates and amounts, never names, addresses, tax IDs or email addresses. Your system reads more with its API key if it needs to:

{
"id": "6f1c…", "type": "invoice.paid", "api_version": "2026-11-01", "created_at": "2026-11-03T02:10:00Z",
"company_id": "1b2e…",
"data": { "object": "invoice", "id": "9a7d…", "doc_no": "IV2026-00042", "status": "posted", "contact_id": "c03e…",
"date": "2026-11-01", "currency": "THB", "total": "535.00", "amount_due": "0.00", "paid": "535.00", "credited": "0.00" }
}

Every message has a Somdul-Signature header: t=<unix time>,v1=<signature>. The signature is HMAC-SHA256 of <t>.<raw body> with the endpoint’s signing secret. Check it before trusting the message, and refuse messages more than 5 minutes old so an old one can’t be replayed. In Node.js:

import { createHmac, timingSafeEqual } from 'node:crypto';
function fromSomdul(rawBody, header, secret) {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
return expected.length === parts.v1?.length && timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}

Use the body exactly as received (before parsing the JSON). Somdul-Event-Id stays the same when a message is sent again, so you can ignore one you have already handled.

Answer with any 2xx status within 10 seconds. Anything else (or no answer) is tried again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and 24 hours: 8 tries in about two days. Redirects are not followed. Before each message Somdul looks up your address, and refuses to send (shown as “blocked”) if it points to a private network, such as 10.x.x.x, 192.168.x.x or this machine. If an endpoint keeps failing for a whole day, Somdul switches it off and tells the company’s admins. Fix your server, tick On again in Edit, and use Send again in Latest deliveries for anything you missed. Messages are usually sent within a minute of the change.

Exactly what happens when a person does the same thing in the app: a posted tax invoice books the sale and output VAT, a posted receipt clears the customer’s balance. The Audit trail shows the admin who made the key, with “via API” and the key’s name underneath.

  • A tax invoice created through the API is the same document as one made in the app. Generally, a full tax invoice must carry the details the Revenue Code requires, so send the customer’s tax ID and branch when you have them.
  • Your own system becomes another place where customers’ personal data is kept. Generally the business is responsible for protecting it under the Personal Data Protection Act B.E. 2562 (PDPA): give each key only the scopes it needs, and revoke keys you no longer use.
  • Putting the key in a website or app → anyone can read it there. Call the API from your server, and revoke a key that may have leaked.
  • Retrying without an Idempotency-Key → a dropped connection can create the same invoice twice. Always send one.
  • Sending amounts as numbers like 1500.5 → send strings with two decimals, "1500.50".
  • Not checking the webhook signature → anyone who learns your address could send fake messages.
  • A slow webhook receiver → answer 200 straight away and do the work afterwards.

Business and Pro (also during a trial), and every client company of an accounting practice. Lite and Free don’t include it.

No. Supplier bills arrive as drafts, so a person checks them against the supplier’s paper and posts them in Somdul.

What happens to a key when its maker leaves?

Section titled “What happens to a key when its maker leaves?”

The key acts as the admin who made it. When that person is no longer an admin of the company, the key stops working. Another admin makes a new key and updates the system that used it.

Use a separate test company in your own organisation: its keys can’t touch any other company. The public demo doesn’t accept keys.