Skip to main content

Context:

I want to send various files from my app to Zapier via webhook. I don’t want to use urls for files.

Currently I am passing base64 encoded data of a pdf inside the payload via webhook to Zapier. 

I have written a JS code which decodes the base64 data. 

I want to attach this data to "attachments" of Gmail and send a pdf as an attachment to this email. 

I am not able to do this.  I have attached a few images to explain better. 

 

Issues:

  • Inside attachment I am writing {{code.attachment}} but it is not working. 
  • Suppose the file object contains content, filename, content type then I am passing this object to output. But when I click on attachment I can't use this object as a whole. The keys get broken down. I can use attachment.content or attachment.filename but not attachment object as a whole. 

What should I do?

 

@Adrika Gupta

Your code is returning an attachment variable, which is set as the file, but the file is an object with 3 parameters.

 

Those correspond to these 3 output variables from the Code step, which can be mapped to following Zap action steps.

 


Isnt file an object?
So to send a pdf as an attachment in gmail inside attachment field, what output variable should I add/write from code step?


@Adrika Gupta

Help article about using files in Zaps: https://help.zapier.com/hc/en-us/articles/8496288813453#limitations-0-0

File objects are the bundles of data that represent the actual file.
This is different from the name of the file or other file attributes. For example, the actual image of an apple is the file object, while the file name might be “apple.jpg”.

 

You can try asking Zapier Support for further guidance: https://zapier.com/app/get-help


I did not understand the file object concept. Can you give an example of using file object inside the attachment field please?


@Adrika Gupta

From the help article: https://help.zapier.com/hc/en-us/articles/8496288813453#limitations-0-0

If a previous step has a File field with an (Exists but not shown) value, that is a file object.

 

Example of a hydrated file object from the Zap trigger: Gmail - New Attachment

 


I am sorry but it is still not clear to me.

I am sending base64 encoded data of a pdf inside the payload to Zapier. 

Using “Code by Zapier”, I decoded the data.

Now I want to attach the decoded data to Attachment field and send it as a pdf.
How can I achieve this? Where am I going wrong?


@Adrika Gupta 

You can try opening a ticket with Zapier Support for further assistance: https://zapier.com/app/get-help

NOTE: Zapier Support generally has limited support for custom code.


Okay.

Can you please give an example of file object? Also how can I attach it in Attachment field?


@Adrika Gupta 

You can try opening a ticket with Zapier Support for further assistance: https://zapier.com/app/get-help

NOTE: Zapier Support generally has limited support for custom code.


Okay! Thank you so much for you help


Hi! I have one last question if you could help me out here.

 

When I am returning an object attachment from the code and using it in Attachment field, how can I use attachment as a single key and not get separate keys for attachment filename, attachment type, attachment content?


Hi @Adrika Gupta 

Good question.

The black icon with ! means the variable is not mapped correctly from a previous step.

 


Okay, so how should I correct it?

I have attached the code image as well in the question.


@Adrika Gupta 

You need to remove the currently mapped variable for Code Attachment, then select the desired output variable from the Code step, that has the value you are trying to use as an attachment.

That must be a file object or a file url.


If you take a look at the code I am returning the object named "attachment"


Inside Attachment field I had written {{code.attachment}} yet it is not working


@Adrika Gupta

Please provide a list of variables returned/output from the Code step, that you can select using the ‘Custom’ mapping option.

NOTE: You are returning a value named “attachment” from the Code step, not a variable named
“Code Attachment”.

 

 

 

For context, here’s an example of a properly mapped variable from a Code step.

Notice the step # (e.g. 2.) that indicates the Step from which the variable is mapped, and the </> icon that indicates the Code step.

 


 

I have attached the screenshots of test action of code by zapier and also the options coming when I click on Attachment field.