Best answer

How to send decode base64 encoded pdf data and attach the pdf in Zapier?

  • 17 February 2023
  • 17 replies
  • 1352 views

Badge

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?

 

icon

Best answer by Adrika Gupta 18 February 2023, 17:07

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

17 replies

Userlevel 7
Badge +14

Hi @Adrika Gupta 

Good question.

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

 

Badge

Okay, so how should I correct it?

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

Userlevel 7
Badge +14

@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.

Badge

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

Userlevel 7
Badge +14

@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.

 

Badge

 

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

 

Userlevel 7
Badge +14

@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.

 

Badge

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?

Userlevel 7
Badge +14

@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

Badge

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

Userlevel 7
Badge +14

@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

 

Badge

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?

Userlevel 7
Badge +14

@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.

Badge

Okay.

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

Userlevel 7
Badge +14

@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.

Badge

Okay! Thank you so much for you help

Badge

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?