Skip to main content

Tasks

Tasks

Associated Terms
Export tasks, Background jobs, Async exports

Contents

Overview

Tasks in Spaaza represent asynchronous background jobs that run on the Services API. The most common use case is exporting data (transactions, users, vouchers, wallet entries, products, and product variants) to CSV or JSON files.

The Services API provides separate hostnames for production and staging environments. Consult your Spaaza contact for the correct hostname for your environment.

A task moves through the following lifecycle:

StateDescription
READYThe task has been created and is waiting for its scheduled time.
INPROGRESSThe task is currently running.
DONEThe task completed successfully. The result file is available.
ERRORThe task failed. Check the task logs for details.

The typical workflow for an export task is:

  1. Create a taskPOST /tasks with export details and a trigger time.
  2. Poll statusGET /tasks/{id} until state is DONE or ERROR.
  3. Download the resultGET /tasks/{id}/download_url returns a temporary pre-signed URL.

Tasks can also be executed immediately without waiting for the scheduled time by calling POST /tasks/{id}/execute.

Task object structure

All endpoints that return a task use the following JSON structure:

FieldTypeDescription
idintegerUnique task identifier.
chainintegerChain ID for which the task was created.
descstringTask description (for reference purposes).
stateobjectCurrent task state (see below).
state.codestringStatus code: READY, INPROGRESS, DONE, ERROR.
state.last_run_datestringISO 8601 datetime of the last run.
state.last_modifiedstringISO 8601 datetime of the last modification.
state.created_datestringISO 8601 datetime when the task was created.
triggerobjectThe trigger configuration (see Scheduling and triggers).
targetobjectThe target configuration (see Target parameters).
logsarrayTask execution log entries (see Log entries).
debugstringDebug string.
versionintegerInternal version number.
resultstringResult filename (populated when state is DONE).

Target parameters

The target object defines what the task does:

FieldTypeDescription
target.actionstringThe action to perform. Use "export" for data exports.
target.export_indexstringThe data index to export. One of: transactions, users, vouchers, wallet-ledger, products, product-variants.
target.export_formatstringThe output format. One of: csv, json.

Log entries

Each entry in the logs array may contain:

FieldTypeDescription
msgstringLog message (e.g. "READY -> INPROGRESS", "success").
timestringISO 8601 datetime of the log entry.
totalintegerTotal records processed (present on completion).
errorsintegerNumber of errors during processing.
skipsintegerNumber of skipped records.
successintegerNumber of successfully processed records.

Scheduling and triggers

The trigger object controls when a task runs and what data it operates on:

FieldTypeRequiredDescription
trigger.oncestringrequiredISO 8601 datetime when the task should execute. Set to a time shortly in the future.
trigger.repeatstringoptionalRepeat schedule after initial run. One of: "daily", "weekly", "monthly". If omitted or empty, the task runs once only.
trigger.segmentobjectconditionalInline segment filter rules. See Segment filter reference.
trigger.segment_idstringconditionalID of a saved segment (from Console). Alternative to inline segment.
note

Either trigger.segment, trigger.segment_id, or neither can be provided. If neither is provided, all records in the index are exported (unfiltered).

When trigger.repeat is set, the task automatically reschedules itself after each run:

Repeat valueBehaviour
"daily"After each run, trigger.once is advanced to the next day.
"weekly"Runs on the same weekday and time, every week.
"monthly"Runs on the same day-of-month and time, every month.

Permissions and Authentication

All tasks endpoints require chain-scoped authentication on the Services API. See the authentication page for more details on authentication methods. The following authentication types are permitted:

  • Privileged authentication: the use of privileged authentication is permitted for all tasks endpoints. This is the recommended method for service-to-service integrations.
  • Admin authentication: the use of admin authentication is permitted. The performing user needs to have the appropriate access level for the chain.

Endpoints

MethodEndpointDescription
POST/tasksCreate a task
GET/tasksList tasks
GET/tasks/{id}Get a task
PUT/tasks/{id}Update a task
DELETE/tasks/{id}Delete a task
GET/tasks/{id}/download_urlGet download URL
POST/tasks/{id}/executeExecute a task