Emailing application file

Should I be able to email an application file using a http api call to sendgrid?
I’m not sure where in the process I need to Base64 encode it and how?

To explain it further, the application file that I want to email has been added there by a Notebook, so maybe it’s better to use it from the payload right after the notebook finishes ?

@Lars_Andersson,

I want to make sure I understand correctly…

You’re looking to use the HTTP Node to make an HTTP request against the SendGrid API to send an email with an attachment, correct? You are not using either the Email Node or the SendGrid Node?

Thank you,
Heath

Correct.
Unless I can do it easier with the nodes you mentioned, but I didn’t think I could?

@Lars_Andersson,

I’m with you, and you should be able to do this. You will need to base64 encode the attachment before the HTTP node.

You could do this with something like the Mutate Node and the encodeBase64 template helper if you would like for the encoded data to remain on the payload for use in another node.

Otherwise, since the HTTP Node Header Values accept string templates, you can use the encodeBase64 helper right in the header value.

Please let me know if you need more information.

Thank you,
Heath

So if I wanted to use the Header Values in the HTTP Node like {{encodeBase64 val}},
should the “val” just be the URL to the application file?

@Lars_Andersson,

I have not tested this. But the information I have been providing you I have found in the SendGrid API Documentation. They have a great, built-in API tester that may be able to assist you.

Thank you,
Heath

I’m struggling a bit with getting the attachment Base64 encoded properly before using the Sendgrid API. I get the error " “The attachment content must be base64 encoded.” from sendgrid.

The Body template in the POST looks like this , where data.response.body is a Losant application file retrieved with a previous HTTP GET node, where Body encoding type is set to Base64(maybe that’s the problem?):

{
“personalizations”: [
{
“to”: [
{
“email”: “redacted”
}
],
“subject”:“redacted”
}
],
“from”:{
“email”:“redacted”
},
“content”:[
{
“type”:“text/plain”,
“value”:“Analytics report attached”
}
],
“attachments”:[
{
“content”:"{{encodeBase64 data.response.body}}",
“filename”:“Report.csv”,
“type”:“application/json”,
“disposition”:“attachment”
}
]
}

As a further info, the file is 798KB.

I believe you’ll need triple curly braces around the base64encode. By default, Handlebars performs HTML escaping and some of the characters in base64, specifically the equal sign, will get escaped.

{{{encodeBase64 data.response.body}}}

In Handlebars, triple curly braces will provide raw, unescaped, content.

Thanks ! that was it.