Document upload using API

I’m having issues uploading documents to be attached to an invoice since migrating to v5 self-hosted. I followed the format from Build, Collaborate & Integrate APIs | SwaggerHub so the request looks like this:

/usr/bin/curl -v -X 'PUT' \
   'https://domain.net/inv/public/api/v1/invoices/QK9b6NlbEv/upload?include=clients%2Cinvoices' \
   -H 'X-Api-Secret: MY_API_SECRET' \
   -H 'X-Api-Token: MY_API_TOKEN' \
   -H 'X-Requested-With: XMLHttpRequest' \
   -F 'file=./Summary-2022-3157.pdf'

The server responds with code 200 and outputs the correct invoice, but the file does not attach to the invoice.

I have tried changing “file=” to “document=” and “documents=” to no avail. What am I missing?

I have also tried swapping -F for -d like this:

/usr/bin/curl -v -X 'PUT' \
   'https://domain.net/inv/public/api/v1/invoices/QK9b6NlbEv/upload?include=clients%2Cinvoices' \
   -H 'X-Api-Secret: MY_API_SECRET' \
   -H 'X-Api-Token: MY_API_TOKEN' \
   -H 'X-Requested-With: XMLHttpRequest' \
   -d ./Summary-2022-3157.pdf

Hi,

There’s an example here:

Thank you! I was able to get it to work using this code. The “documents[0]” seems to be very important.

/usr/bin/curl -v -X POST \
   'https://domain.net/inv/public/api/v1/invoices/O5xe70ra7r/upload
   -H 'Content-Type: multipart/form-data' \
   -H 'X-Api-Token: MY_API_TOKEN' \
   -H 'X-Requested-With: XMLHttpRequest' \
   -F  _method=PUT \   
   -F 'documents[0]=@./Summary-2022-3157.pdf'
1 Like

How did you figure out the [0]???

documents[0]

Thank you for making the time to contribute this information.
You’re a lifesaver.