# Losant API " Event Export" as attachment, not email link

**URL:** <https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473>\
**Category:** Help\
**Tags:** losant-api\
**Created:** [May 14, 2024, 9:16pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473 "2024-05-14T21:16:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 14, 2024, 9:16pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/1 "2024-05-14T21:16:29Z")

</div>

Im trying to export event data on a 60-90 basis ( as part of a regulatory requirement ).  
I am able to get the required data in my workflow gathered and the generic LOSANT email sent to the client of my choosing, but can not rely on the clients opening and saving the data beforethe url expires. So I need to actually emai the \*.csv file to them as an attachment.

I have yet to find find a way to retrieve/find that file once created by the API and attach it. Any help appreciated

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 15, 2024, 1:18pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/2 "2024-05-15T13:18:57Z")

</div>

Just yesterday we [released a new template](https://app.losant.com/applications/recent/template-library?templateId=6643bffa73921ccae24a75ef) that is remarkably close to your use case - the main difference being you are doing event exports and this template does dashboard reports. I would recommend importing this template into your application and seeing if you can modify it to fit your use case.

One note of caution is, event export calls are [limited to one request every five minutes per application](https://docs.losant.com/rest-api/overview/#throttles-and-limits), so you have to make some modifications to the template - the resource job and the workflow - to avoid running into this limit. I just filed a request with the engineering team to get that changed to one concurrent request per application.

As to your specific questions … I am assuming you are using the Events: Export call with the “email” option (sending the export file directly to your users) and not the “callbackUrl” option (which would send the link as an HTTP POST request to a URL of your choosing once the report has been generated - usually a [Losant Webhook](https://docs.losant.com/applications/webhooks/)). You would only be able to retrieve the URL to the file if you were using the “callbackUrl” option, which you could then use to …

1. [Trigger a workflow](https://docs.losant.com/workflows/triggers/webhook/) from the webhook URL provided as the callbackUrl
2. Download the file’s contents with an [HTTP Node](https://docs.losant.com/workflows/data/http/)
3. Send it to your user using the [SendGrid Node](https://docs.losant.com/workflows/outputs/sendgrid/), which supports sending attachments

Lots to take into account there, so I would definitely start from the template i mentioned before. Let us know if you have any other questions.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 17, 2024, 2:48pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/3 "2024-05-17T14:48:41Z")

</div>

Dylan  
Thank you for your reply. I was previously able to configure the Losant API to process a “Event Export” and use the “experienceGroupId” to set the main client email address as the reciever of the email along with the group the exported events were associated with.  
But I as I mentioned if the client does not download it soon, the link expires ( I do not know exactly how long the link is valid).

Currently I am triggering with a virt button , but I am able to iterate over all child groups with a Group Tag(s) that adds a suitable time to run the next report given the last export success so the iteration thru the client data is handled on more a “timer” than your example.

What I need to do is email the attachment to the client for their records , not the link.  
It looks as if your workflow accomplishes that at some point but when I water it down ( remove dashboard, iteration & token references) change the job execute to point to a Event Export resource job rather than Dashboard I have no success. The error is iteration related althought Im confident I removed all those references.

Regards,

Stewart

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 17, 2024, 3:20pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/4 "2024-05-17T15:20:02Z")

</div>

> But I as I mentioned if the client does not download it soon, the link expires ( I do not know exactly how long the link is valid).

The signed URLs expire 7 days after issuance.

> What I need to do is email the attachment to the client for their records , not the link.  
> It looks as if your workflow accomplishes that at some point

There is a [SendGrid Node](https://docs.losant.com/workflows/outputs/sendgrid/) in the template’s workflow that is not attached to the rest of the output; its configuration mostly matches the Email Node that is in the flow, except the SendGrid Node does support sending attachments so it is configured to do that instead of just sending a link. This requires you to create your own SendGrid account and do a little setup on the Losant side to add your API key in a [service credential](https://docs.losant.com/applications/credentials/#sendgrid) for the node - but, as we tell people often, we strongly recommend this approach for production applications as the [Email Node](https://docs.losant.com/workflows/outputs/email/) often gets flagged as spam.

There is an alternative approach you could take - instead of emailing the signed URL that expires to your end users, you could …

1. Download the file’s contents using the HTTP Node.
2. Use a [File: Create Node](https://docs.losant.com/workflows/data/file-create/) to save it to your Application Files.
3. Email the user the link to the file as it’s stored in your files vs. sending the signed URL, as the files link will never expire.

That same template demonstrates something very similar to what I’m describing here, connected to the [Job: Complete Trigger](https://docs.losant.com/workflows/triggers/job-complete/); we are downloading the job’s completion report and saving it to our files. You could take those same nodes and bring it into the [Job: Iteration Trigger](https://docs.losant.com/workflows/triggers/job-iteration/) section to do something similar.

The downside to this approach is that **anything in Application Files should be considered public** - meaning anybody who got hold of the link could download the contents without any kind of authorization checks. Because of that, this may not be an acceptable solution for you.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 22, 2024, 11:25pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/5 "2024-05-22T23:25:14Z")

</div>

Dylan

Got it working adequately for my needs.

One last detail is that templating in the sendgrid node does not work. {{EventData}}.csv as attachment name, {{groupName}} as subject both return blank.

Stew

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 23, 2024, 12:44am UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/6 "2024-05-23T00:44:04Z")

</div>

What is the payload you are rendering those templates against? Both of those fields do support templating so you are likely referencing a property that is undefined.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 23, 2024, 1:38pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/7 "2024-05-23T13:38:41Z")

</div>

Dylan,  
They were defined. {{child\_group\_loop.value.name}} for example is appearing in a debug node correctly.When used in the sendgrid node : "{{child\_group\_loop.value.name}}, Your Magchecks Event Data Report Is Attached… ", returns “, Your Magchecks Event Data Report Is Attached…” in the email subject line

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 23, 2024, 4:22pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/8 "2024-05-23T16:22:35Z")

</div>

Dylan,  
I think I may see the issue. I modifed the example workflow to include a loop which iterates over all my clients and then picks one ( based on when the last export occured and some other criteria) and then runs the API request etc… As the sendgrid node is outside of that loop no references to the payload inside the loop seems possible.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 23, 2024, 4:37pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/9 "2024-05-23T16:37:06Z")

</div>

That would do it, yes.

If your loop is only picking one, an easy fix would be to just put the SendGrid Node back into the loop and your references should work again.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 23, 2024, 4:50pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/10 "2024-05-23T16:50:40Z")

</div>

Dylan,

The webhook trigger cant be moved to inside the loop. My modifications to the example attached.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/0141b685b4316196dd92200ef7f9a1fcf75b99b9.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [May 23, 2024, 4:57pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/11 "2024-05-23T16:57:26Z")

</div>

Well in that case, if you’re using a webhook to receive the callback, you can just pass the values through as query parameters. For example, change your `callbackUrl` to …

```auto
https://triggers.losant.com/YOUR_UNIQUE_WEBHOOK_URL?groupName={{child_group_loop.value.name}}&fileName={{path.to.filename}}.csv

```

Then, in the Webhook Trigger, those values are available on the payload under `data.query.groupName` and `data.query.fileName`.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [May 23, 2024, 5:19pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/12 "2024-05-23T17:19:15Z")

</div>

I took the easy way 🙂 , I copied the two values I needed ( Group Name and Group Email) to storage vaules inside the loop, then retreived them to place in sendgrid node.

Seems to work ok.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [June 20, 2024, 1:50pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/13 "2024-06-20T13:50:23Z")

</div>

FYI, [Tuesday’s platform update](https://www.losant.com/blog/platform-update-http-features-and-mongodb-service-credential) changed the throttling rules to allow one concurrent events export per application, as opposed to one every five minutes, so that should hopefully improve your use case here.

---

<div class="post-metadata">

**Author:** ![Stewart\_McCallum](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/stewart_mccallum/32/2490_2.png) [@Stewart\_McCallum](https://forums.losant.com/u/Stewart_McCallum)\
**Post date:** [June 20, 2024, 2:13pm UTC](https://forums.losant.com/t/losant-api-event-export-as-attachment-not-email-link/5473/14 "2024-06-20T14:13:36Z")

</div>

Thanks for the update Dylan
