One key, one company
Every WonderFatoora company is a separate account with its own VAT number, invoice sequence and ZATCA link. A key belongs to exactly one company, and the seller on every invoice is the key's company. No request field can choose another company; a company or seller identifier sent in the body is ignored.
Case A: your SaaS bills its own customers
You are the seller. Your company has a WonderFatoora account and an API key; each of your customers is a buyer on your invoices.
- Create a key for your company with
invoices:write,invoices:issueandinvoices:read. - When a payment succeeds, create the invoice with
external_referenceset to your payment or billing-period id. - Store the returned
customer.idwith your customer record and reuse it next time. - Read the invoice until
zatca.deliverableistrue, then sendpublic_urlwith your receipt.
The SaaS billing API page walks through this in full. A server app you registered in My apps can do the same with OAuth client credentials: its token acts for your own company only.
Case B: your customers invoice their buyers through your product
Each of your customers is a seller and needs their own WonderFatoora company, on a plan that includes app connections (the plans with API access). Each customer connects their company to your app once, through OAuth:
- Register your app in Settings → Developers → My apps, with your exact redirect URI and the scopes your product needs.
- Your customer clicks "Connect WonderFatoora" in your product. Send them to
/oauth/authorizewith PKCE and astate. - They sign in, choose their company and approve. You receive a code at your redirect URI; exchange it at
/oauth/tokenfor an access token and a refresh token, and store the refresh token encrypted against that customer. - The token response names the company (
company_id), and every API answer repeats it inmeta.company_id. Your token for one customer can never reach another customer's data. - Your customer can disconnect your app at any time from their dashboard; their tokens stop at once. Handle
401 invalid_tokenby asking them to connect again.
Usage counts against each customer company's own plan, and every call shows in their request log under your app's name.
Without OAuth, the same works with one key per customer company:
- Your customer creates a key in their WonderFatoora account, with only the scopes your product needs, and enters it in your product.
- Store each key encrypted, linked to that customer's account. Never share a key between companies.
- Call the API with the key of the company the invoice belongs to. Confirm the pairing once with
GET /ping, which returns the company name. - Your customer can revoke the key in their account at any time. Handle
401by asking them to reconnect.
Isolation
- A key reads and writes only its own company's data. An invoice or customer id from another company is answered exactly like an id that does not exist.
- Product and tax-rate ids are checked against the key's company.
- Every call is logged against the key that made it.
Ready to build?
API access is part of the Business and Enterprise plans. Create a key in Settings → API keys and make your first call in minutes.