I am trying to make an automation on Zapier with the flow like this:
- 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 isstr
- Action: a Zapier Python Code that retrieve the
file
from web hooks, decode the base64 string tobytes
to get the real valid content of the PDF to say a variable namedfile_bytes
- 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:
- pass the
file_bytes
to output like so:
output = [{'file': input_data['file_bytes']}]}]
but it gave me This must be JSON serializable!
- 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)
- pass the
file_bytes
as decoded string withlatin-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?