Execute a task over HTTP
To run task JavaScript via the API, send a POST to:
POST /api/1/endpoint/execute
Request body
Send JSON or form-encoded data with:
| Field | Description |
|---|---|
name | Function or task name to execute. |
sourceCode | JavaScript to run in the sandbox. |
inputDocument | JSON string of the input payload (your initial payload). |
options | JSON string of context (user, params, changed fields, etc.). |
metadata[case_type_code] | Optional; helps identify the function. |
metadata[account_nickname] | Optional; helps identify the account. |
Example body (JSON)
{
"name": "test_function",
"sourceCode": "payload.result = 'ok'; exit(payload);",
"inputDocument": "{\"foo\": \"bar\"}",
"options": "{\"current_user\": {\"id\": 1, \"email\": \"user@example.com\"}}",
"metadata[case_type_code]": "demo",
"metadata[account_nickname]": "acme"
}
The options object
When parsed inside the sandbox, options may include:
current_user— User running the task (id,email,display_name,account_code, etc.).params— Arbitrary parameters for this run.changed_fields— Map of field names to[before, after]pairs when relevant.requestContext— Transaction context (may be set automatically).authorization— Token when present (may be set automatically).
Example options (JSON)
{
"current_user": {
"id": 21,
"email": "acme@caseblocks.local",
"display_name": "Acme",
"account_code": "acme"
},
"params": { "x": "1" },
"changed_fields": {
"current_state": ["Verified", "Not Started"],
"_title": [null, "test"]
}
}
Writing sourceCode
Use the provided payload and finish with exit(payload) on success, or fail('reason') on validation errors.
Minimal success
payload.status = 'processed';
exit(payload);
Validation failure
if (!payload.foo) {
fail('Missing foo!');
}
exit(payload);
Example cURL
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '{"metadata[case_type_code]": "bulk_uplift","name": "test","sourceCode": "payload.test=\"success\"\n exit(payload)","inputDocument": "{\"title\": \"sample\"}","options": "{}","metadata[account_nickname]": "ccexpo"}' \
"http://localhost:8000/api/1/endpoint/execute"
Adjust host and metadata for your environment.
See also
- Scripting environment —
exit,fail,log,delay,payload. - Built-in functions —
graphql, HTTP helpers, etc.