There are 2 different ways to add attachments through the API, depending on what exactly you want to achieve.

  • Add an attachment to the invoice itself
  • Add an attachment while sending the email

Both options use a different API call.

Add attachment while sending

When sending the invoice, you can also add additional files.

Uploading these additional files is done through a separate call.


Use the POST method with the following URL:
https://eenvoudigfactureren.be/api/v1/uploads.


Send the file as form-data using the key ‘file’. The file size may not exceed 5MB. You can upload multiple files at once by using ‘file[]’. Optionally, you can also provide a filename using the key ‘filename’.


The response returns a list containing the following information for each uploaded file:


upload_id: Use this when sending the email (attachments argument)

filename: The provided filename (this is not stored permanently and must be provided again when sending the attachment by email).

available_until: The validity period during which the file remains available (up to 1 hour after uploading the file).


$p = curl_init('https://eenvoudigfactureren.be/api/v1/uploads');
curl_setopt($p, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key_here",
    "Accept: application/json",
]);
curl_setopt($p, CURLOPT_POSTFIELDS, [
    'file' => new CURLFile('/path/to/attachment.pdf'),
    'filename' => 'attachment.pdf'
]);
curl_setopt($p, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($p);
if (curl_errno($p)) {
    echo 'Error: ' . curl_error($p);
} else {
    echo $response;
}
curl_close($p);


Add attachment to the invoice itself

Uploading

To add a new attachment, use /upload.
For example: POST https://eenvoudigfactureren.be/api/v1/invoices/3003/files/upload


$p = curl_init('https://eenvoudigfactureren.be/api/v1/invoices/3003/files/upload');
curl_setopt($p, CURLOPT_HTTPHEADER, [
    "X-API-Key: your_api_key_here",
    "Accept: application/json"
]);
curl_setopt($p, CURLOPT_POSTFIELDS, [
    'file' => new CURLFile('/path/to/attachment.pdf'),
    'filename' => 'attachment.pdf',
    'role' => 'attachment'
]);
curl_setopt($p, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($p);
if (curl_errno($p)) {
    echo 'Error: ' . curl_error($p);
} else {
    echo $response;
}
curl_close($p);


Downloading

To retrieve the contents of the attachment, use /download.
For example: GET https://eenvoudigfactureren.be/api/v1/invoices/3003/files/8764/download