Script Webhooks
Script Webhooks
Every script in the Script Engine has a webhook URL — a single HTTPS endpoint
that runs the script when you send it an HTTP POST. Use it to trigger a script from an
external application, a scheduled job on another system, a form submission, a Plex automation, or a
one-line curl command. Whatever JSON you post becomes the script's input.
Finding the webhook URL
Open a script in the Script Engine editor. Next to the script's ID chip in the header you'll see a Webhook button. Click it to open a popover that shows:
- the exact callable URL, with a Copy button;
- a ready-to-paste
curlexample; - a reminder of how to authenticate.
The URL follows this pattern, where {id} is the numeric Script ID:
POST https://data-magik.com/api/script-engine/scripts/{id}/execute
Authentication
Webhook calls authenticate with a DataMagik API key. Create one under
Your Account > API Keys; keys start with dcp_. Send it as a header:
X-API-Key: dcp_your_api_key_here
An Authorization: Bearer dcp_your_api_key_here header works identically. The key's
user must hold the DataMagik - Builder or DataMagik - Viewer
permission, and the script runs in that user's company context.
Sending data to the script
Post any JSON object as the request body — the script receives it verbatim as its
context. For example, this request:
curl -X POST https://data-magik.com/api/script-engine/scripts/482/execute \
-H "X-API-Key: dcp_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{ "orderId": 12345, "notify": true }'
...is read inside the script like this:
function main(context) {
const id = context.orderId; // 12345
if (context.notify) { /* ... */ }
}
context. The body must be a JSON object; a bare
array, string, or number is rejected with a 400 error. You can optionally pin a script version or
priority with the X-Script-Version-Id and X-Script-Priority headers.What the webhook returns
Short scripts finish inline; longer ones continue in the background so your caller never hangs.
- Finished in time — HTTP 200. The response includes
execution_id,completed: true, and anexecutionobject with the script'soutput_data, status, anyerror_message, run time, API-call count, and console logs. - Still running — HTTP 202. The response includes the
execution_idand astatus_url. PollGET /api/script-engine/executions/{execution_id}(or stream.../executions/{execution_id}/stream) to get the final result.
Where runs show up
Every webhook run is recorded in the script's execution history, with its console logs, output, and any errors — the same place scheduled and manual runs appear. If a call fails, check the response body first (auth or bad-JSON errors come back immediately), then the execution history for runtime errors inside the script.