Skip to Content
Docs

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. 1

    Create the document

    content_length is 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 status created. See Create a document.

  2. 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 the content_type you 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.pdf

    A successful upload returns 204 with no body. Use --data-binary, because curl's -d strips line breaks from a file, which corrupts it. See Upload document contents for samples in each language.

  3. 3

    Wait for the scan

    The document is pending while it's scanned, then active or rejected. Listen for document.active and document.rejected webhooks, or retrieve the document until its status changes.

    curl https://api.sandbox.pay.com/v1/documents/$DOCUMENT_ID \
      -u ":$PAY_COM_API_KEY"
  4. 4

    Download the file

    Only an active document has contents to download. Before that, the request returns 404. The response is the file itself, with its Content-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.

LimitValue
Upload size50 MB. Files over 50 MB return HTTP 413.
Size that doesn't match content_lengthRejected by the API. Create a new document with the exact byte size.
A document used as dispute evidence10 MB and 50 pages by default. Some processors allow less.

When the document is active, send its ID to Submit dispute evidence.

Next steps

Was this page helpful?