Upload file to a document
curl --request POST \
--url https://clarus-api.com/api/documents/{id}/upload \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--header 'X-Clarus-Subdomain: <api-key>' \
--form file=@example-fileimport requests
url = "https://clarus-api.com/api/documents/{id}/upload"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {
"Authorization": "Bearer <token>",
"X-Clarus-Subdomain": "<api-key>"
}
response = requests.post(url, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'X-Clarus-Subdomain': '<api-key>'}
};
options.body = form;
fetch('https://clarus-api.com/api/documents/{id}/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": 123,
"type": "documents",
"attributes": {
"category": "report",
"file_name": null,
"file_path": null,
"file_type": null,
"status": "queued",
"user_id": 1
}
}
}{
"error": "<string>"
}{
"errors": [
{
"code": 123,
"symbol": "<string>",
"details": "<string>",
"source": "<string>",
"context": {}
}
]
}{
"errors": [
{
"code": 123,
"symbol": "<string>",
"details": "<string>",
"source": "<string>",
"context": {}
}
]
}Documents
Upload file to a document
Upload the file content of an existing document record. The document must be in queued or processing status. On success, the document status changes to available.
POST
/
api
/
documents
/
{id}
/
upload
Upload file to a document
curl --request POST \
--url https://clarus-api.com/api/documents/{id}/upload \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--header 'X-Clarus-Subdomain: <api-key>' \
--form file=@example-fileimport requests
url = "https://clarus-api.com/api/documents/{id}/upload"
files = { "file": ("example-file", open("example-file", "rb")) }
headers = {
"Authorization": "Bearer <token>",
"X-Clarus-Subdomain": "<api-key>"
}
response = requests.post(url, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'X-Clarus-Subdomain': '<api-key>'}
};
options.body = form;
fetch('https://clarus-api.com/api/documents/{id}/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": 123,
"type": "documents",
"attributes": {
"category": "report",
"file_name": null,
"file_path": null,
"file_type": null,
"status": "queued",
"user_id": 1
}
}
}{
"error": "<string>"
}{
"errors": [
{
"code": 123,
"symbol": "<string>",
"details": "<string>",
"source": "<string>",
"context": {}
}
]
}{
"errors": [
{
"code": 123,
"symbol": "<string>",
"details": "<string>",
"source": "<string>",
"context": {}
}
]
}Upload Format
This endpoint takes amultipart/form-data request (not JSON:API format) with the file in a file field. The file name and MIME type are taken from the uploaded file.
When sending multipart, don’t set the Content-Type header yourself. Your HTTP client sets multipart/form-data with the boundary when you attach the file.
Example (cURL)
curl -X POST https://clarus-api.com/api/documents/42/upload \
-H 'Authorization: Bearer <token>' \
-H 'X-Clarus-Subdomain: acme-warehouse' \
-F '[email protected];type=text/csv'
Status Transitions
- Document must be in
queuedorprocessingstatus - After successful upload, status becomes
available - If the document is already
availableorfailed, the upload will be rejected
Deprecated: raw body upload
Sending the raw file as the request body is still accepted but deprecated and will be removed. Until you switch to multipart, keep sending both headers:Content-Type with the file’s MIME type and Content-Disposition: attachment; filename="<name>".
