Skip to main content

Export data to a CSV file and deliver it

A common automation: fetch a set of records, turn them into a CSV file, and send that file to another system. The chain looks like this — click any step for what it does:

Click a step to see what it does.

How it works

  1. Start hands off to the first action.
  2. Rest (GetData) fetches the rows to export — here, from a named analytics query.
  3. Csv (CreateCsv) turns those rows into a CSV, choosing which columns to include with dataColumns.
  4. Rest (DeliverFile) sends the file on, attaching it as Base64 with the ToBase64 pipe: {{['CreateCsv']$ | ToBase64}}.
  5. Result returns the outcome.

The full automation

ExportExpensesToCsv
[
{
"actionType": "Start",
"name": "Start",
"next": "GetData"
},
{
"actionType": "Rest",
"name": "GetData",
"next": "CreateCsv",
"Method": "POST",
"bodyMediaType": "Json",
"url": "https://apiv2.example.com/api/analytics/globalQuery/Expense - Export/execute",
"body": "{}"
},
{
"actionType": "CreateCsv",
"name": "CreateCsv",
"next": "DeliverFile",
"hasHeaderRecord": true,
"delimiter": ",",
"quote": "\"",
"data": "{{['GetData'].Content.Data}}",
"dataColumns": [
"Employee",
"CostCenter",
"TotalValue",
"ExpenseDate"
]
},
{
"actionType": "Rest",
"name": "DeliverFile",
"next": "Exit",
"Method": "POST",
"bodyMediaType": "Raw",
"url": "https://intake.example.com/api/files",
"body": "{\"fileName\":\"expenses.csv\",\"content\":\"{{['CreateCsv']$ | ToBase64}}\"}",
"requestHeaders": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
{
"actionType": "Result",
"name": "Exit",
"httpResponse": {
"statusCode": 200,
"headers": {},
"body": "{{['DeliverFile']}}"
}
}
]
Adapt it

Change the query URL and dataColumns to your data, and point DeliverFile at wherever the file should go. To email the file instead, swap DeliverFile for an E-mail action — see Send an email notification.