Is it possible to create an expense and upload a document in 1 API call?


Is it possible to fire a single api POST-call to create an expense AND to attach a document to this expense at the same time?

In the end, i’m trying to write a IFTTT-script that I can forward a received email to, and the IFTTT-script creates an expense based on this email and also adds the attached PDF to the created invoice.

Judging on the way Invoice Ninja works, I guess this is not possible, but still wondering if I missed something.



@david can you please advise?


Yes, on any entity it is possible to create and upload in a single call. Just attach your files to the ‘documents’ key in your request.

Dear @david,

Thanks for you answer. I looked at the way the api returns document data in JSON format and tried replicating that to built the body of the POSTcall:

So i have the following:

POST call to https://app_url/api/v1/expenses

“public_notes”: “Filetest5”,
“amount”: 1234,
“documents”: [
“type”: “pdf”,
“url”: “

This call works, i get a 200 OK response, but the file is not uploaded, nor returned in a subsequent api get call…

Any idea how to structure the body of the POST request so that the file can join the ride?



when uploading a document you’ll need to change to a multipart/form-data Content-Type

Here is a working example

curl -X POST \
 http://ninja.test:8000/api/v1/clients/1YQdJ2dOGp/upload \
 -H 'Content-Type: multipart/form-data'\
 -H 'X-API-TOKEN: tokeytoken' \
 -H 'X-Requested-With: XMLHttpRequest' \
 -F _method=PUT \
 -F documents=@/home/david/settings.txt;


Thanks for this pointer! I managed to get your script working. I changed a few settings to create an expense and attach files in one go. Pasted below for future reference:

curl -X POST \
 https://myappurl/api/v1/expenses \
 -H 'Content-Type: multipart/form-data' \
 -H 'X-API-TOKEN: tokeytoken' \
 -H 'X-Requested-With: XMLHttpRequest' \
 -F 'public_notes= thisworks!' \
 -F 'documents[0]=@/Users/Desktop/test.pdf';

Mark the [0] I had to put in the documents field.

Sadly enough, I still haven’t figured out a way to get Zapier or IFTTT to attach a received emailattachment to the webrequest.
I’ll keep digging to see if i can find anything and will post here if i manage to get it working. If anybody has an idea, please let me know!

1 Like