1

I am trying to make an automation on Zapier with the flow like this:

  1. Trigger: a web hook that receive POST request. The body is a file key with a value of base64 string of a certain PDF, so the type is str
  2. Action: a Zapier Python Code that retrieve the file from web hooks, decode the base64 string to bytes to get the real valid content of the PDF to say a variable named file_bytes
  3. Action: a dropbox that retrieve the file_bytes from the step before, and upload it to dropbox

I coded the decoder myself (point 2) and tested that it worked well on my local system.

The problem is that Dropbox (point 3) only receive binary, while Python (point 2) can not pass a value other than JSON serializable. This is a clear limitation from Zapier:

output A dictionary or list of dictionaries that will be the "return value" of this code. You can explicitly return early if you like. This must be JSON serializable!

...

The close to what I can get from other question on this sites are these two, but it did not give me any luck.

...

The code to decode base64 string to bytes is like so:

file_bytes = base64.b64decode(input_data['file'])

What I already did:

  1. pass the file_bytes to output like so:
output = [{'file': input_data['file_bytes']}]}]

but it gave me This must be JSON serializable!

  1. pass the file_bytes as string like so:
output = [{'file': str(input_data['file_bytes'])}]

it do uploaded to dropbox, but the file content is corrupt. (of course it is, duh)

  1. pass the file_bytes as decoded string with latin-1 encoding:
output = [{'file': input_data['file_bytes'].decode('latin-1')}]

it do uploaded to dropbox, the PDF can also be opened, even having the same page number as the original PDF, but it is all blank (white, no content)

...

So, is this kind of feature really visible in Zapier platform? Or I was already at dead end even since the beginning?

  • Rahmat have you considered attempting to upload the file using Dropbox's API? You could, using python's requests library, POST the raw data to Dropbox. This would allow greater control over how you get information into your account. Take a look at Dropbox's developer site https://www.dropbox.com/developers/documentation/http/documentation#files-upload – Michael Case May 13 '19 at 19:44

0 Answers0