Documents API
Documents
Attach a file to an existing invoice, sales order, quote, purchase bill, purchase order, expense, deposit, transfer, journal, or payment. The file is not sent to this API. Request a PUT URL, upload the bytes to that URL, then confirm. Branch is SelectedBranchId. Do not send branch_id.
Send rtype and record_id with the exact values below. record_id is the numeric id returned when you create or list that record.
rtype (exact value) | Attaches to | record_id |
|---|---|---|
invoice | Invoice | Invoice id |
sales_order | Sales order | Sales order id |
quote | Quote | Quote id |
purchase_bill | Purchase bill | Purchase bill id |
purchase_order | Purchase order | Purchase order id |
expense | Expense | journals_id |
income | Deposit | journals_id |
transfer | Transfer | journals_id |
journal | Journal | journals_id |
customer_payment | Customer payment | journals_id |
supplier_payment | Supplier payment | journals_id |
Use these strings as written. Do not send Expense, Income, Deposit, Customer_Payment, Supplier_Payment, or purchase. purchase_order is a purchase order, not a purchase bill. income is a deposit.
The caller needs edit access for that module. A retail invoice needs retail invoice edit access.
Get upload params
GET https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-params
- cURL
- JavaScript
curl -X GET 'https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-params' \
-H 'Authorization: Bearer <personal_access_token>' \
-H 'SelectedBranchId: <numeric_branch_id>'
const response = await fetch("https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-params", {
method: "GET",
headers: {
Authorization: "Bearer <personal_access_token>",
SelectedBranchId: "<numeric_branch_id>",
},
});
const data = await response.json();
console.log(data);
Any authenticated caller. Returns allowed file extensions and the size limit in megabytes.
Example response
{
"success": true,
"message": "Upload params fetched successfully",
"result": {
"extension": [
".doc",
".docx",
".jpeg",
".jpg",
".png",
".pdf",
".ppt",
".pptx",
".svg",
".xls",
".xlsx",
".csv",
".mov",
".avi",
".mp4",
".mkv",
".dwg",
".dxf",
".zip",
".rar",
".fig",
".ai",
".psd",
".skp",
".ifc",
".rvt",
".dae",
".3ds",
".obj",
".dxfx",
".ls11",
".ls12"
],
"size_limit": 10
}
}
size_limit is megabytes. extension values include the leading dot.
Create a document upload URL
POST https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-url
- cURL
- JavaScript
curl -X POST 'https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-url' \
-H 'Authorization: Bearer <personal_access_token>' \
-H 'SelectedBranchId: <numeric_branch_id>' \
-H 'Content-Type: application/json' \
-d '{
"record_id": 4452,
"rtype": "invoice",
"file_name": "scan.pdf",
"file_size": 102400,
"extension": "pdf"
}'
const response = await fetch("https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document/upload-url", {
method: "POST",
headers: {
Authorization: "Bearer <personal_access_token>",
SelectedBranchId: "<numeric_branch_id>",
"Content-Type": "application/json",
},
body: JSON.stringify({
"record_id": 4452,
"rtype": "invoice",
"file_name": "scan.pdf",
"file_size": 102400,
"extension": "pdf"
}),
});
const data = await response.json();
console.log(data);
Creates a draft document and a short-lived PUT URL. PUT the file bytes to upload_url before it expires. Do not send Authorization on that PUT.
Body
| Field | Required | Type | Description |
|---|---|---|---|
record_id | Yes | number | Bill id or journals_id for the rtype |
rtype | Yes | string | Exact value from the Documents table above |
file_name | Yes | string | Original file name. Maximum 200 characters |
file_size | Yes | number | File size in bytes. Must be greater than 0 and within size_limit |
extension | Yes | string | File extension with or without a leading dot. Must be in extension from Get upload params |
Example request
{
"record_id": 4452,
"rtype": "invoice",
"file_name": "scan.pdf",
"file_size": 102400,
"extension": "pdf"
}
Example response
{
"success": true,
"message": "Upload URL generated",
"result": {
"file_id": 1025,
"upload_url": "https://...presigned-s3-put-url...",
"upload_method": "PUT",
"url_expires_at": "2026-10-19T10:35:00+00:00"
}
}
url_expires_at is five minutes after the URL is created.
Errors
record_id is Mandatoryrtype is Mandatoryfile_name is Mandatoryfile_size is Mandatoryextension is Mandatoryrtype must be invoice, sales_order, quote, purchase_bill, purchase_order, expense, income, transfer, journal, customer_payment, or supplier_paymentrecord_id is requiredInvoice not foundSales order not foundQuote not foundPurchase bill not foundPurchase order not foundExpense not foundDeposit not foundTransfer not foundJournal not foundPayment not foundInvalid file_sizeInvalid file formatFile exceeds upload size limitCharacter limit of 200 exceeded for file_nameUnable to generate upload URLPermission Denied
Confirm a document
POST https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document
- cURL
- JavaScript
curl -X POST 'https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document' \
-H 'Authorization: Bearer <personal_access_token>' \
-H 'SelectedBranchId: <numeric_branch_id>' \
-H 'Content-Type: application/json' \
-d '{
"title": "test data",
"file_id": 1025,
"record_id": 4452,
"rtype": "invoice"
}'
const response = await fetch("https://yoursite.ealsuite.com/?app=ealsuite_api/v1/document", {
method: "POST",
headers: {
Authorization: "Bearer <personal_access_token>",
SelectedBranchId: "<numeric_branch_id>",
"Content-Type": "application/json",
},
body: JSON.stringify({
"title": "test data",
"file_id": 1025,
"record_id": 4452,
"rtype": "invoice"
}),
});
const data = await response.json();
console.log(data);
Publishes the draft from Create a document upload URL and attaches it to the record. Call this after the PUT to upload_url succeeds. file_id must be a draft created by the calling user in this branch.
Body
| Field | Required | Type | Description |
|---|---|---|---|
file_id | Yes | number | file_id from the upload URL response |
record_id | Yes | number | Same bill id or journals_id used to create the upload URL |
rtype | Yes | string | Same rtype used to create the upload URL |
title | No | string | Display title. Must not contain special characters. When omitted or empty, the original file name without extension is used |
Example request
{
"title": "test data",
"file_id": 1025,
"record_id": 4452,
"rtype": "invoice"
}
Example response
{
"success": true,
"message": "Document attached successfully",
"result": {
"id": 1025
}
}
Errors
file_id is Mandatoryrecord_id is Mandatoryrtype is Mandatoryrtype must be invoice, sales_order, quote, purchase_bill, purchase_order, expense, income, transfer, journal, customer_payment, or supplier_paymentrecord_id is requiredInvoice not foundSales order not foundQuote not foundPurchase bill not foundPurchase order not foundExpense not foundDeposit not foundTransfer not foundJournal not foundPayment not foundDocument title should not contain special charactersDocument not foundAll Fields are RequiredPermission Denied