File Exports
A file export runs a saved view on a schedule and delivers the result as a file to your own server. Use it to feed a data warehouse, a finance system or a partner that only takes files.
For example, a coffee chain sends yesterday's points earned and redeemed, by store, to its finance team's SFTP server at 6 AM every day.
Before you start
You need a saved view: a named query over your program's analytics. Create one with POST /analytics/saved-views, or start from a template listed at GET /analytics/saved-view-templates. Check its result with GET /analytics/saved-views/{id}/results before you schedule it.
Create an export
curl -X POST https://api.loomloyalty.com/file-exports \
-H "Authorization: Bearer $LOOM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily points by store",
"savedViewId": "svvw_123",
"cronExpression": "0 6 * * *",
"timeZone": "America/New_York",
"format": "CSV",
"destination": {
"destinationType": "SFTP",
"host": "files.example.com",
"port": 22,
"username": "loyalty-exports",
"remoteDirectory": "/incoming/loyalty",
"hostKeyFingerprint": "SHA256:YOUR_HOST_KEY_FINGERPRINT"
}
}'
| Field | Required | Description |
|---|---|---|
name | yes | A label for the export. |
savedViewId | yes | The saved view whose result the export delivers. |
cronExpression | yes | The schedule: 5 fields (minute, hour, day of month, month, day of week), or 6 with seconds first. |
timeZone | no | The time zone the schedule runs in, such as America/New_York. Defaults to UTC. |
format | yes | CSV, or PSV for pipe-separated values. |
destination | yes | Where the file goes (below). |
SFTP destination
The response carries a publicKey. Authorize it for the export's user on your server, for example by adding it to that user's authorized_keys. Weave signs in with that key and refuses a server whose host key doesn't match hostKeyFingerprint (as ssh-keygen -lf prints it). The host must be reachable on the public internet. port defaults to 22.
Cloud storage destination
You can also deliver to a cloud storage bucket instead of an SFTP server. The API reference lists the destination's fields and what you grant Weave on your side.
Test the destination
Send a small test file before the first scheduled run:
curl -X POST https://api.loomloyalty.com/file-exports/fexp_123/test-delivery \
-H "Authorization: Bearer $LOOM_API_KEY"
This writes loom-test-<timestamp>.txt to the destination without running the saved view, and returns the test run. A failed run carries an errorCode, such as DESTINATION_UNREACHABLE, DESTINATION_AUTH_FAILED, DESTINATION_HOST_KEY_MISMATCH or DESTINATION_ADDRESS_BLOCKED.
Runs
Each run ends DELIVERED or FAILED. List an export's runs, newest first, with GET /file-exports/{id}/runs. Each run shows what started it (SCHEDULE, MANUAL or TEST), the file name, row count and size. Runs are kept for 30 days.
- Run now:
POST /file-exports/{id}/runsqueues a manual run. The schedule is unchanged. - Download a copy:
GET /file-exports/{id}/runs/{runId}/download-urlreturns a short-lived link to the delivered file. Files are kept for 30 days. - Webhooks: subscribe to
file_export.deliveredandfile_export.failedto hear about each scheduled or manual run.
Pause and resume
POST /file-exports/{id}/pause stops the schedule. POST /file-exports/{id}/resume starts it again, computes the next run from now and resets the count of failed runs. An export that fails too many times in a row pauses itself, and consecutiveFailures shows how close it is.
To change an export, PUT /file-exports/{id} with only the fields you want to change. A new destination replaces the old one in full, and changing its type generates a new key.