# Emailing application file

**URL:** <https://forums.losant.com/t/emailing-application-file/3762>\
**Category:** Help\
**Tags:** workflow\
**Created:** [April 30, 2021, 5:49pm UTC](https://forums.losant.com/t/emailing-application-file/3762 "2021-04-30T17:49:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [April 30, 2021, 5:49pm UTC](https://forums.losant.com/t/emailing-application-file/3762/1 "2021-04-30T17:49:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [April 30, 2021, 5:53pm UTC](https://forums.losant.com/t/emailing-application-file/3762/3 "2021-04-30T17:53:18Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [April 30, 2021, 6:13pm UTC](https://forums.losant.com/t/emailing-application-file/3762/4 "2021-04-30T18:13:44Z")

</div>

@Lars_Andersson,

I want to make sure I understand correctly…

You’re looking to use the [HTTP Node](https://docs.losant.com/workflows/data/http/) 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](https://docs.losant.com/workflows/outputs/email/) or the [SendGrid Node](https://docs.losant.com/workflows/outputs/sendgrid/)?

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [April 30, 2021, 6:17pm UTC](https://forums.losant.com/t/emailing-application-file/3762/6 "2021-04-30T18:17:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [April 30, 2021, 6:38pm UTC](https://forums.losant.com/t/emailing-application-file/3762/8 "2021-04-30T18:38:09Z")

</div>

@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](https://docs.losant.com/workflows/logic/mutate/) and the [`encodeBase64` template helper](https://docs.losant.com/workflows/accessing-payload-data/) 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](https://docs.losant.com/workflows/data/http/#header-configuration) 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

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [April 30, 2021, 6:43pm UTC](https://forums.losant.com/t/emailing-application-file/3762/10 "2021-04-30T18:43:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [April 30, 2021, 7:09pm UTC](https://forums.losant.com/t/emailing-application-file/3762/12 "2021-04-30T19:09:09Z")

</div>

@Lars_Andersson,

I have not tested this. But the information I have been providing you I have found in the [SendGrid API Documentation](https://sendgrid.com/docs/api-reference/). They have a great, built-in API tester that may be able to assist you.

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [May 26, 2021, 7:14pm UTC](https://forums.losant.com/t/emailing-application-file/3762/14 "2021-05-26T19:14:01Z")

</div>

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”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [May 26, 2021, 8:05pm UTC](https://forums.losant.com/t/emailing-application-file/3762/16 "2021-05-26T20:05:55Z")

</div>

As a further info, the file is 798KB.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [May 26, 2021, 8:11pm UTC](https://forums.losant.com/t/emailing-application-file/3762/17 "2021-05-26T20:11:39Z")

</div>

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.

```nohighlight
{{{encodeBase64 data.response.body}}}

```

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

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [May 26, 2021, 8:49pm UTC](https://forums.losant.com/t/emailing-application-file/3762/18 "2021-05-26T20:49:02Z")

</div>

Thanks ! that was it.
