REST API
Read and write Records, call RPC functions and upload files over HTTP.
Every endpoint lives on the site's own host, such as https://erp.acme.com/api/.... Bodies are JSON. Success is {"data": ...}. Every failure is {"error": {"type", "message", "fields"}}.
Authenticate
A user with write on a User's API key field generates a key pair:
curl -X POST https://erp.acme.com/api/auth/keys \
-H 'Content-Type: application/json' -b cookies.txt -H "x-cardinal-csrf: $CSRF" \
-d '{"user": "integration@acme.com"}'
# {"api_key": "3f9a1c2b7d8e4f60", "api_secret": "..."}The secret is shown once. Send the pair on every request:
curl https://erp.acme.com/api/rec/Customer -H "Authorization: token $KEY:$SECRET"Bearer KEY:SECRET and Basic auth over the same pair work too. Requests with a key need no CSRF token.
Records
:rectype is the RecType name, URL-encoded (Sales%20Invoice), or its desk slug (sales-invoice).
| Method and path | Does |
|---|---|
GET /api/rec/:rectype | List. 20 rows unless limit is set |
GET /api/rec/:rectype/count | Count. cap=N stops at N |
GET /api/rec/:rectype/new | Defaults for a new Record |
POST /api/rec/:rectype | Insert |
GET /api/rec/:rectype/:name | Read, with recinfo (your rights on it) |
PUT /api/rec/:rectype/:name | Save. The body must carry the modified you read |
DELETE /api/rec/:rectype/:name | Delete |
POST .../:name/submit, /cancel, /discard, /amend | Docstatus actions |
POST .../:name/rename | {"new_name": "...", "merge": false} |
GET .../:name/copy | The Record a Duplicate starts from |
GET .../:name/timeline | Versions, comments and communications, newest first |
GET .../:name/recinfo | Your rights and field levels, plus a page of Versions, Comments and Files (limit up to 500) |
GET .../:name/connections | The Connections panel: linked RecTypes with the count of linked Records you may read |
GET /api/meta/:rectype | The RecType's compiled metadata. Needs a signed-in user |
A single's Record is /api/rec/:rectype/:rectype, such as /api/rec/System%20Settings/System%20Settings. A PUT or submit without the modified you read is a 409.
List parameters are JSON in the query string: fields, filters, or_filters, limit, offset and distinct. order_by and group_by are text. A JSON null is the same as leaving the key out.
In fields | Means |
|---|---|
* | Every column you may read |
items.item_code | A column of the items Table field's rows |
count(*), sum(qty), avg(rate), min(f), max(f) | Aggregates. With group_by, need the report right |
month(posting_date), quarter(...), year(...), day(...) | Date buckets for group_by |
purpose=export marks a page of a CSV export. It needs the export right and reads within the first 10,000 rows. Naming a column you cannot read is a 403.
A write whose controllers raised warnings answers them as warnings: [...] beside data.
curl -G https://erp.acme.com/api/rec/Sales%20Invoice \
-H "Authorization: token $KEY:$SECRET" \
--data-urlencode 'fields=["name","customer","grand_total"]' \
--data-urlencode 'filters=[["status","=","Overdue"],["grand_total",">","1000"]]' \
--data-urlencode 'order_by=posting_date desc' \
--data-urlencode 'limit=50'Money and other decimals travel as strings ("1250.00"). A JSON number for a Currency field is refused. Datetimes are RFC 3339 in UTC, ending in Z.
RPC
Apps expose functions at /api/rpc/<app>.<module>.<function>, POST by default. Only functions the app marks @rpc answer, and each declares who may call it.
curl -X POST https://erp.acme.com/api/rpc/core.search.link \
-H "Authorization: token $KEY:$SECRET" -H 'Content-Type: application/json' \
-d '{"rectype": "Customer", "txt": "acme"}'
# {"data": [{"value": "CUST-0001", "label": "Acme Ltd", "description": ""}]}Core's own functions are listed in RPC functions. A GET passes arguments in the query string. A multipart POST works only for core.web_form.accept.
Files
POST /api/file takes multipart form data: a file part plus is_private ("0" makes a public File), attached_to_rectype, attached_to_name and attached_to_field. A file over the site's max_file_size is a 413 and leaves nothing behind.
GET /api/file/:name redirects to a download URL that lives 300 seconds. ?download=1 makes the browser save the file.
Response headers
Every /api response of a site, except an immutable one, carries x-cardinal-meta and x-cardinal-perm, the site's metadata and permission versions, and x-request-id. The desk compares the version headers with its cache to know when its metadata is stale. API responses also send frame-ancestors 'none' and nosniff.
Errors
| Type | Status | When |
|---|---|---|
Validation | 422 | A value was refused. fields lists each as {path, code, message} |
BadRequest | 400 | Malformed query or body |
Authentication | 401 | Not signed in, or a failed login |
Permission | 403 | You lack the right |
CSRF | 403 | A session request without its token |
NotFound | 404 | Unknown Record, RecType, function or host |
TimestampMismatch | 409 | The Record changed since you read it |
LinkExists | 409 | Other Records link to it. links lists them |
DuplicateEntry | 409 | The name is taken |
PayloadTooLarge | 413 | Body over 8 MB, or a file over the limit |
RateLimited | 429 | Too many attempts. See Retry-After |
Unavailable | 503 | The site is not active |
Internal | 500 | A server error. Quote trace_id when you report it |