Upload and download files
Create a document, send its file, wait for the scan, and download it.
Documents are the files you submit as dispute evidence. You create a document with the file's name and exact size, upload the file to it, and use it once it has been scanned. Your key needs Write on Documents.
Upload and download a document
Create a document record, upload the binary file, wait for virus scanning to complete, and download the active file.
- 1
Create the document
content_lengthis the file's size in bytes. The upload must be exactly that size.SIZE=$(wc -c < receipt.pdf | tr -d ' ') curl https://api.sandbox.pay.com/v1/documents \ -u ":$PAY_COM_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "filename": "receipt.pdf", "reference": "order_12345", "content_type": "application/pdf", "content_length": '"$SIZE"' }'The response has the document's
id, with the statuscreated. See Create a document. - 2
Upload the file
Send the file as the request body, without multipart or JSON around it, with the file's own
Content-Type. That type replaces thecontent_typeyou gave when you created the document.curl https://api.sandbox.pay.com/v1/documents/$DOCUMENT_ID/upload \ -u ":$PAY_COM_API_KEY" \ -H 'Content-Type: application/pdf' \ --data-binary @receipt.pdfA successful upload returns
204with no body. Use--data-binary, because curl's-dstrips line breaks from a file, which corrupts it. See Upload document contents for samples in each language. - 3
Wait for the scan
The document is
pendingwhile it's scanned, thenactiveorrejected. Listen fordocument.activeanddocument.rejectedwebhooks, or retrieve the document until its status changes.curl https://api.sandbox.pay.com/v1/documents/$DOCUMENT_ID \ -u ":$PAY_COM_API_KEY" - 4
Download the file
Only an
activedocument has contents to download. Before that, the request returns404. The response is the file itself, with itsContent-Type.curl https://api.sandbox.pay.com/v1/documents/$DOCUMENT_ID/contents \ -u ":$PAY_COM_API_KEY" \ --fail --output document.pdf
Limits
Uploads have a size limit, and documents used as dispute evidence have lower limits.
| Limit | Value |
|---|---|
| Upload size | 50 MB. Files over 50 MB return HTTP 413. |
Size that doesn't match content_length | Rejected by the API. Create a new document with the exact byte size. |
| A document used as dispute evidence | 10 MB and 50 pages by default. Some processors allow less. |
When the document is active, send its ID to
Submit dispute evidence.
Next steps
- Create a document: full request and response schema for document creation.
- Submit dispute evidence: attach an
activedocument to a dispute. - Webhooks: listen for
document.activeanddocument.rejectedevents.