Can't attach PDF Documents

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.

@zmccarty56

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

@zmccarty56

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 :slight_smile: , 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 Thank you for posting this! I’ll give it a try this weekend and see if it works out.

@fredz @david How can I get this to work with a Zapier request? I’m not working with local files but instead URLs

@zmccarty56

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 :pray:

Ok I copied @fredz code exactly and still getting error “method not supported”

import urllib.request
import requests
url = ‘https://pdf-temp-files.s3.us-west-2.amazonaws.com/SXEZJ0JB5WEIWHWMWYSJTAXP0VZ1N0A4/time_sheet.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEKb%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDLb4KNNO%2BAaqBIov6iKCAaAvNsbCY8OFqdUJN5NessGwhHAjYaJnyy%2FoHbUtdqi8LMokqOsluS5O8tI9ljtK0cfcC9A0UM4eNXTAQ9EAnWUxh%2BYxDiMuj7O3rYA%2BCQzA%2BzJ0zoX3WcJR07g%2BkAmnykuWIk7awa62kgVd5OvNRtRJtbD8KQRLtZ1abCCP0vL8S%2BAoy4H7ngYyKFL1PYjZbYuNRw4Ql2awLxiIYI08aqNCt%2F2ycpn%2BOwI3KmDopjriHag%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHB5ALEGL4/20230204/us-west-2/s3/aws4_request&X-Amz-Date=20230204T203706Z&X-Amz-SignedHeaders=host&X-Amz-Signature=f33b3272ecd8bde3a675ac1caa7b077146cd28ae4fbe1fa445dcbe03d00215f5

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 ?

1 Like

@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)
2 Likes

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