Lovely, I appreciate the level of support you are giving.
I am going to try and think of a work around for this in the meantime.
Lovely, I appreciate the level of support you are giving.
I am going to try and think of a work around for this in the meantime.
There was a slight error in my CURL request
curl -X POST \
http://ninja.test:8000/api/v1/invoices/WJxboVzagw/ \
-H 'Content-Type: multipart/form-data'\
-H 'X-API-TOKEN: company-token-test' \
-H 'X-Requested-With: XMLHttpRequest' \
-F _method=PUT \
-F documents[]=@/home/david/x.pdf;
The documents key must be an array. I’ve tested this from CURL and can confirm it works. I would expect from zapiers end the import things to ensure are that the content type is set correctly, and that the request is a POST request but the _method: PUT must also be in the body - this particular point is a quirk with PHP.
@david Even with this update, I’m still stumped. Been on this for months now…
See below how zapier webhook is being configured. The only difference I can even see is that the key for the file is “file” here instead of “documents” is that what is holding us back here?
When I run this without including the file url it does succeed but obviously just doesn’t add anyting
I deleted the image due to the exposed x-api-token, you’ll want to redact that from your screenshots as it is an account security issue.
The key we look for in regards to files is “documents” we expect this to be an array (to allow multiple documents to be uploaded at once)
I’m not sure how Zapier is handling it on their side, but we definitely need the file rather than the reference URL.
One year after , there is a working version for python requests. As @david commented, the trick is to add “_method”:“PUT” in data and do a post request :
import requests
headers = {
'X-API-TOKEN': 'WLEyIKsii8JHPPOY4MGBEuEzjA8Gcg71DXPraodGtahgtrMXL7HYG2C40Lzj',
'X-Requested-With': 'XMLHttpRequest',
}
local_name = "time_sheet.pdf"
response = requests.post(
'https://invoicing.co/api/v1/invoices/pnelKrqVdKz/upload',
headers=headers,
data={"_method":"PUT"},
files={"documents[]":open(local_name, "rb")
)
@fredz @david How can I get this to work with a Zapier request? I’m not working with local files but instead URLs
The app is expecting a file, not URL, you would need to see if Zapier could pull the file first and then push.
What would it take to beg you guys for a zapier integration for this
Ok I copied @fredz code exactly and still getting error “method not supported”
urllib.request.urlretrieve(url, “time_sheet.pdf”)
headers = {
‘Content-Type’: ‘multipart/form-data’,
‘X-API-TOKEN’: ‘Token Goes HERE’,
‘X-Requested-With’: ‘XMLHttpRequest’,
}
local_name = “time_sheet.pdf”
response = requests.post(
‘https://invoicing.co/api/v1/invoices/oeE8K1pWd0/upload’,
headers=headers,
data={“_method”:“PUT”},
files={“documents[]”:open(local_name, “rb”)})
print(response.status_code)
print(response.text)
Hi, could you try without the “Content-Type” header ?
@fredz I could kiss you right now…it worked!!!
Posting my final python code for anyone that has this need in the future
url = '<url of file here'
urllib.request.urlretrieve(url, "<file name>")
headers = {
'X-API-TOKEN': <api token here>',
'X-Requested-With': 'XMLHttpRequest'
}
local_name = <name of file>
response = requests.post(
'https://invoicing.co/api/v1/invoices/<invoice_id>/upload',
headers=headers,
data={"_method":"PUT"},
files={"documents[]":open(local_name,'rb')})
print(response.status_code)
print(response.text)
Glad to hear it’s working, thanks for sharing the working code!
Thanks for all the collaboration here. 1 whole year in the making haha