Magbiz ERP API documentation

Your system can create customers, issue and approve documents, and follow payments in Magbiz through an “API user”. Every request goes through the same permissions and rules as the staff screens.

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 POST to https://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 the what field; business errors are returned with HTTP 200.
  • Use error_code in your program · msg is a Thai message for people · a wrong, expired or revoked token returns error.TokenNotFound.
  • Documents are referenced by id in the form <organization id>-<document number>, e.g. 12-IN2611/00001 · dates use YYYY-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_ref is 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 be https to a host on the internet · the response contains a whsec_… secret once, used to verify signatures.
  • ERP sends a POST with 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 carries v1 = 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)

FieldTypeMeaning
user_id *stringAPI user id
code *stringUsername
role *stringRole
org_id *stringOrganization id
branchstringBranch
warehousestringDefault warehouse
hook_urlstringWebhook URL (empty = not set)
hook_last_okstringTime of the last successful webhook
hook_last_errorstringLast 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

FieldTypeMeaning
urlstringAn https URL to a host on the internet · empty = remove

Response (info)

FieldTypeMeaning
url *stringThe URL set
secretstringThe 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

FieldTypeMeaning
idstringCustomer to update
client_refstringYour reference to avoid duplicates — for new records only (rejected together with id)
codestringCustomer code
namestringCustomer name
contact_typestringC company · P individual
tax_nostringTax ID
info_bnamestringBilling name
info_baddressstringBilling address
info_bphonestringBilling phone
info_bemailstringBilling email
remarkstringRemark

Response (info)

FieldTypeMeaning
id *stringCustomer id (use as the document contact_id)
codestringCustomer code
namestringCustomer name
replayedstringY = 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

FieldTypeMeaning
master *stringMaster data set
statusstringA = active only

Response (info)

FieldTypeMeaning
code *stringCode
text *stringName
statusstringStatus

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

FieldTypeMeaning
idstringDocument to update
client_refstringYour reference to avoid duplicates — for new records only (rejected together with id)
doc_type *stringDocument type, e.g. IN invoice · TI tax invoice · BC billing contract · GJ journal voucher · PV payment voucher
doc_date *stringDocument date
contact_idstringCustomer or vendor
owner_idstringOwner
ref_doc_nostringReference document number
price_optionstringIn prices include VAT · Ex prices exclude VAT
remarkstringRemark
detailarrayLines: no code name qty unit price · documents that settle others use ref_doc_no amount

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet total calculated by ERP
replayedstringY = 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

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet total calculated by ERP
doc_datestringDocument date
contact_idstringCustomer or vendor
paidnumberAmount paid
cnnumberAmount credited
detailarrayDocument 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

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)
status *stringA approve · C cancel
reasonstringReason (required to cancel)

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet total calculated by ERP

POST /document/payments — Payments and credits of a document

Receipts and credit notes still in effect against this document

Request

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)

Response (info)

FieldTypeMeaning
doc_no *stringDocument number
payments *arrayEach 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

FieldTypeMeaning
doc_typestringDocument type · billing = let ERP pick an invoice or tax invoice from the settings
credit_termstringCredit term (used with billing)
notestringText appended to the default remark
contact_idstringCustomer — returns the bill-to details
acc_rolesarrayAccount roles whose account codes you need

Response (info)

FieldTypeMeaning
doc_typestringDocument type
remarkstringDefault remark
bill_toobjectBill-to info_ fields, ready to put on the document
accounts *objectAccount 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

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet total calculated by ERP

POST /billing_contract/end — End a contract

Stops billing the next periods

Request

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet total calculated by ERP

POST /billing_contract/cancel — Cancel a contract

Allowed while no period document is in effect

Request

FieldTypeMeaning
id *stringDocument (<organization id>-<number>)
reasonstringReason

Response (info)

FieldTypeMeaning
id *stringDocument id
doc_no *stringDocument number
doc_type *stringDocument type
status *stringStatus (D draft · A approved · C cancelled · some document types have more)
net_totalnumberNet 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

FieldTypeMeaning
kind *stringdoc
id *stringDocument (<organization id>-<number>)
daysstringLink lifetime 7, 30 or 90 days (default 30)

Response (info)

FieldTypeMeaning
url *stringFull link
links *arrayAll links of the document: id tail state (active expired revoked) created_time expire_time view_count
payobjectInvoices: outstanding wht to_transfer

POST /doc_share/list — Links of a document

Links created and their state (without the full link)

Request

FieldTypeMeaning
kind *stringdoc
id *stringDocument (<organization id>-<number>)

Response (info)

FieldTypeMeaning
links *arrayAll links of the document
payobjectAmount the customer has to pay (invoices)

POST /doc_share/revoke — Revoke a link

The link stops working immediately

Request

FieldTypeMeaning
share_id *stringThe link id from links

Response (info)

FieldTypeMeaning
links *arrayAll 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

FieldTypeMeaning
period *stringMonth YYYY-MM (not a closed period)
account *stringBalance sheet account code
amountstringExpected amount (baht)
contactsarrayPer customer: contact_id amount — replaces the previous set
notestringNote (up to 250 characters)

Response (info)

FieldTypeMeaning
period *stringMonth
account *stringAccount code
amount *stringAmount saved
Free 30-day trial

Ready to run your business
in one system?

Sign up for a trial yourself right now, or ask about pricing and custom work — use whichever channel suits you.