1. Getting started
- The business owner creates an API user at Settings › API users and picks a role — the API user can do exactly what that role can do on screen.
- Issue a token valid for 30, 90 or 365 days. The token is shown once and starts with
mbapi_— keep it in a secure place in your system. You can revoke it at any time on the same page. - API users have no password and cannot sign in to the web app; they do not count as package users. Every change is recorded in the activity log as “sent via API”.
- Test the connection with
/api_user/me— it returns the API user and the organization of the token.
2. Requests and responses
- Every endpoint is
POSTtohttps://erpservice.magbizcloud.com/<path>with a JSON body (Content-Type: application/json) — send{}when an endpoint takes no input. - Send the token with every request in the
Authorization: Bearer mbapi_…header. - Success =
{"what": "ok", "info": …}· failure ={"what": "error", "error_code": "error.…", "msg": "…"}— always decide by thewhatfield; business errors are returned with HTTP 200. - Use
error_codein your program ·msgis a Thai message for people · a wrong, expired or revoked token returnserror.TokenNotFound. - Documents are referenced by
idin the form<organization id>-<document number>, e.g.12-IN2611/00001· dates useYYYY-MM-DD· amounts are in baht. - ERP always calculates totals, tax and document numbers from the lines you send; totals from outside systems are not accepted.
curl -X POST https://erpservice.magbizcloud.com/api_user/me \
-H "Authorization: Bearer mbapi_…" \
-H "Content-Type: application/json" \
-d "{}"
3. API versions
- This page describes API v1 · the OpenAPI 3.1 file of this version is at /openapi/v1.json.
- Within v1, the fields and endpoints described here will not be removed or change meaning · new response fields or endpoints may be added, so your system should ignore fields it does not know.
- Changes that would break connected systems will be released as a new version with its own documentation.
4. Avoiding duplicates with client_ref
- Send
client_ref(up to 100 characters) when creating a new document (/document/update) or customer (/customer/update) — sending the same value again returns the existing record instead of creating a duplicate, so retries after a network failure are safe. - A document created with
client_refis an “external system document” — status changes of that document, and of receipts or credit notes against it, are sent by webhook.
5. Webhook
- Set the URL with
/api_user/hook— it must behttpsto a host on the internet · the response contains awhsec_…secret once, used to verify signatures. - ERP sends a
POSTwith the body{"event": "document.changed", "id", "org_id", "doc_no", "doc_type", "ext_ref", "occurred_at"}— it only says which document changed; read the current state with/document/detail(events may repeat or arrive out of order). - The
X-Magbiz-Signature: t=<unix>,v1=<hex>header carriesv1= HMAC-SHA256 with the secret over<t>.<request body>· verify it and reject timestamps more than 5 minutes off. - Reply with HTTP 2xx once received · otherwise ERP retries after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours, and drops the event after 24 hours.
6. Endpoint reference
Every endpoint is called with an API user token and works within the permissions of its role · fields marked * are required.
API user
POST /api_user/me — The API user of this token
Tests the connection · returns the API user, organization and webhook status
Request
No input — send {}
Response (info)
| Field | Type | Meaning |
|---|---|---|
user_id * | string | API user id |
code * | string | Username |
role * | string | Role |
org_id * | string | Organization id |
branch | string | Branch |
warehouse | string | Default warehouse |
hook_url | string | Webhook URL (empty = not set) |
hook_last_ok | string | Time of the last successful webhook |
hook_last_error | string | Last webhook error |
POST /api_user/hook — Set or remove the webhook
Send url to set it and get a new secret · send it empty to stop
Request
| Field | Type | Meaning |
|---|---|---|
url | string | An https URL to a host on the internet · empty = remove |
Response (info)
| Field | Type | Meaning |
|---|---|---|
url * | string | The URL set |
secret | string | The whsec_… signing secret, shown once |
Customers and master data
POST /customer/update — Create or update a customer
Without id a new customer is created
Request
| Field | Type | Meaning |
|---|---|---|
id | string | Customer to update |
client_ref | string | Your reference to avoid duplicates — for new records only (rejected together with id) |
code | string | Customer code |
name | string | Customer name |
contact_type | string | C company · P individual |
tax_no | string | Tax ID |
info_bname | string | Billing name |
info_baddress | string | Billing address |
info_bphone | string | Billing phone |
info_bemail | string | Billing email |
remark | string | Remark |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Customer id (use as the document contact_id) |
code | string | Customer code |
name | string | Customer name |
replayed | string | Y = this client_ref was sent before; the existing record is returned, nothing new is created |
POST /master/list — List master data
The organization's master data of one set, e.g. payment_period payment terms
Request
| Field | Type | Meaning |
|---|---|---|
master * | string | Master data set |
status | string | A = active only |
Response (info)
| Field | Type | Meaning |
|---|---|---|
code * | string | Code |
text * | string | Name |
status | string | Status |
Documents
POST /document/update — Create or update a document
Without id a new draft (D) is created · fields match the document form on screen; extra fields of each type start with info_ · an owner_id other than the API user can be set after the document is created
Request
| Field | Type | Meaning |
|---|---|---|
id | string | Document to update |
client_ref | string | Your reference to avoid duplicates — for new records only (rejected together with id) |
doc_type * | string | Document type, e.g. IN invoice · TI tax invoice · BC billing contract · GJ journal voucher · PV payment voucher |
doc_date * | string | Document date |
contact_id | string | Customer or vendor |
owner_id | string | Owner |
ref_doc_no | string | Reference document number |
price_option | string | In prices include VAT · Ex prices exclude VAT |
remark | string | Remark |
detail | array | Lines: no code name qty unit price · documents that settle others use ref_doc_no amount |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
replayed | string | Y = this client_ref was sent before; the existing record is returned, nothing new is created |
POST /document/detail — Read a document
The whole document: header, lines (detail), amount paid (paid), credited (cn) and info_ fields
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
doc_date | string | Document date |
contact_id | string | Customer or vendor |
paid | number | Amount paid |
cn | number | Amount credited |
detail | array | Document lines |
POST /document/status — Approve or cancel a document
The same checks as the on-screen buttons — the role needs that button · cancelling needs a reason
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
status * | string | A approve · C cancel |
reason | string | Reason (required to cancel) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
POST /document/payments — Payments and credits of a document
Receipts and credit notes still in effect against this document
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
doc_no * | string | Document number |
payments * | array | Each item: source_doc_no source_doc_type amount wht (withholding tax) wht_cert (certificate received) |
POST /document/defaults — Defaults for a new document
Values ERP derives from the organization settings, so your system keeps no copy of them
Request
| Field | Type | Meaning |
|---|---|---|
doc_type | string | Document type · billing = let ERP pick an invoice or tax invoice from the settings |
credit_term | string | Credit term (used with billing) |
note | string | Text appended to the default remark |
contact_id | string | Customer — returns the bill-to details |
acc_roles | array | Account roles whose account codes you need |
Response (info)
| Field | Type | Meaning |
|---|---|---|
doc_type | string | Document type |
remark | string | Default remark |
bill_to | object | Bill-to info_ fields, ready to put on the document |
accounts * | object | Account codes for the roles asked |
Recurring billing contracts
POST /billing_contract/start — Start a billing contract
If already due, ERP issues the first period's document per the contract settings
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
POST /billing_contract/end — End a contract
Stops billing the next periods
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
POST /billing_contract/cancel — Cancel a contract
Allowed while no period document is in effect
Request
| Field | Type | Meaning |
|---|---|---|
id * | string | Document (<organization id>-<number>) |
reason | string | Reason |
Response (info)
| Field | Type | Meaning |
|---|---|---|
id * | string | Document id |
doc_no * | string | Document number |
doc_type * | string | Document type |
status * | string | Status (D draft · A approved · C cancelled · some document types have more) |
net_total | number | Net total calculated by ERP |
Customer links
POST /doc_share/create — Create a customer link
A link to view the document and report payment without signing in · the full link is in this response only
Request
| Field | Type | Meaning |
|---|---|---|
kind * | string | doc |
id * | string | Document (<organization id>-<number>) |
days | string | Link lifetime 7, 30 or 90 days (default 30) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
url * | string | Full link |
links * | array | All links of the document: id tail state (active expired revoked) created_time expire_time view_count |
pay | object | Invoices: outstanding wht to_transfer |
POST /doc_share/list — Links of a document
Links created and their state (without the full link)
Request
| Field | Type | Meaning |
|---|---|---|
kind * | string | doc |
id * | string | Document (<organization id>-<number>) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
links * | array | All links of the document |
pay | object | Amount the customer has to pay (invoices) |
POST /doc_share/revoke — Revoke a link
The link stops working immediately
Request
| Field | Type | Meaning |
|---|---|---|
share_id * | string | The link id from links |
Response (info)
| Field | Type | Meaning |
|---|---|---|
links * | array | All links of the document |
Period close
POST /month_end/expect — Report an expected month-end balance
The balance your system expects for one account, shown in the month-end checklist for the accountants to compare · the role must be able to edit the checklist
Request
| Field | Type | Meaning |
|---|---|---|
period * | string | Month YYYY-MM (not a closed period) |
account * | string | Balance sheet account code |
amount | string | Expected amount (baht) |
contacts | array | Per customer: contact_id amount — replaces the previous set |
note | string | Note (up to 250 characters) |
Response (info)
| Field | Type | Meaning |
|---|---|---|
period * | string | Month |
account * | string | Account code |
amount * | string | Amount saved |