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
Just yesterday we released a new template 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, 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). 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 …
- Trigger a workflow from the webhook URL provided as the callbackUrl
- Download the file’s contents with an HTTP Node
- Send it to your user using the SendGrid Node, 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.
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
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 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 for the node - but, as we tell people often, we strongly recommend this approach for production applications as the Email Node 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 …
- Download the file’s contents using the HTTP Node.
- Use a File: Create Node to save it to your Application Files.
- 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; 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 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.
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
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.
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
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.
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.
Dylan,
The webhook trigger cant be moved to inside the loop. My modifications to the example attached.
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 …
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
.
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.
FYI, Tuesday’s platform update 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.
Thanks for the update Dylan