REST API

Documentation


File transfer

Files can be supplied in two different ways. Back in the step Order we briefly showed how to supply files as URLs when creating an order:

"files": {
    "content": "https://www.printapi.nl/sample-book-a5-content.pdf",
    "cover": "https://www.printapi.nl/sample-book-a5-cover.pdf"
}
Refer to our FAQ for information on how to format files.

Print API will then automatically download the files asynchronously. This usually happens within 5 minutes. Should a download fail for any reason, you'll receive an automatic error report per e-mail. If this is a suitable solution for your application, you can skip ahead to the next step.

Are your files not publicly available from a webserver? Then read on: you can also upload your files to the API after you've placed an order.

Alternative Uploading

Alternatively, you can upload your files after creating an order. Print API will generate a unique uploadUrl for each file you need to supply. You can then simply POST each file directly to its upload URL. These URLs will be in the API response of your order.

To enable uploads, you must first omit the files-object from your order data, or set it to null in its entirety: this will tell the API to wait for uploads. You can find the uploadUrl at the following location within the API response of your order:

"items": [
    {
        "id": "18557",
        ...
        "files": {
            "content": {
                "status": "AwaitingUpload",
                "uploadUrl": "https://test.printapi.nl/v2/files/05WTSKLi4fVVXog4qw8"
            }
        }
    }
]

To upload the file, send an HTTP POST to the uploadUrl, with the file content directly in the request body. You don't have to construct a complex multipart/form-data request — the following will suffice:

Request:
POST /v2/files/05WTSKLi4fVVXog4qw8 HTTP/1.1
Authorization: Bearer TOKEN
Content-Type: application/pdf

<binary inhoud>

Be sure to specify the correct Content-Type header for the file type you're using, so the API knows how to process your file. The table below shows the value associated with each file type.

File type Content-Type
PDF *.pdf application/pdf
PNG *.png image/png
JPEG *.jpg, *.jpeg image/jpeg
Ordering multiple items with unique files?

To map the right files to the right items, it might help to store some metadata when creating your order:

Excerpt "POST /orders" request
{
    "productId": "poster_a4_sta",
    "quantity": 100,
    "metadata": "{ \"file\" => \"e7JkW4YVNE1qg6iRMBZ3.png\" }"
}

You can use the metadata-field to store your own data, like a file path or file ID. It's just a text field, so JSON, XML or plain text are all fine. When uploading, you could use this field to map each item back to its file:

Excerpt "POST /orders" response
"items": [
    {
        "id": "18557",
        "metadata": "{ \"file\" => \"e7JkW4YVNE1qg6iRMBZ3.png\" }",
        ...
        "files": {
            "content": {
                "status": "AwaitingUpload",
                "uploadUrl": "https://test.printapi.nl/v2/files/05WTSKLi4fVVXog4qw8"
            }
        }
    }
]
Next