Respond to Wrkflow Sync API
Sends a response body and optional headers to the synchronous caller of the current Wrkflow. This works for both a Sync API launch and a sync webhook.
Application
- Launch
Inputs (what you have)
| Name | Description | Data Type | Required? | Example |
|---|---|---|---|---|
| Wrkflow output | Response body sent to the synchronous caller | Text (Long) | Yes | {"ok":true,"result":42} |
| Wrkflow output headers | Array of headers, each with a headerName and headerValue | Array | No | See the JSON response example below |
HTTP status and application results
When the caller receives the response produced by this action, the HTTP status is 200. The action has no HTTP status input. Setting a field such as status or statusCode in Wrkflow output, or adding a header named Status, does not configure the HTTP status.
An application error returned in the body still uses HTTP 200. For example, a validation branch can send {"ok":false,"error":{"code":"INVALID_INPUT"}}. The caller must inspect that body to distinguish an application error from a successful result. The action's Success outcome means the response action completed; it does not mean the body reports application success or that the entire Wrkflow has finished.
This applies to responses produced by this action. A rejected launch, transport failure, or timeout before the action responds is a separate condition; do not treat every synchronous request as guaranteed to return HTTP 200 or this body schema.
JSON response example
Choose a body schema shared by the Wrkflow and its caller. The following ok, result, and error fields are an example convention you define, rather than fields added by Wrk.
Set Wrkflow output headers to:
[{"headerName": "Content-Type", "headerValue": "application/json"}]
On the successful branch, set Wrkflow output to valid JSON text:
{"ok": true, "result": {"value": 42}}
On a validation-error branch, send an error body:
{
"ok": false,
"error": {
"code": "INVALID_INPUT",
"message": "Quantity must be a positive integer."
}
}
Both bodies are returned with HTTP 200. Build JSON with a JSON serializer when inserting dynamic values so quotes, newlines, and other characters are escaped correctly.
A JavaScript caller can check the HTTP status and then validate the agreed body envelope:
async function readWrkflowResponse(response) {
if (response.status !== 200) {
throw new Error(`Sync response unavailable (HTTP ${response.status})`);
}
const body = await response.json(); // Rejects malformed JSON.
if (
body === null ||
typeof body !== 'object' ||
Array.isArray(body) ||
typeof body.ok !== 'boolean'
) {
throw new Error('Unexpected Wrkflow response body');
}
if (!body.ok) {
throw new Error('Wrkflow reported an application error');
}
if (!Object.hasOwn(body, 'result')) {
throw new Error('Wrkflow response is missing result');
}
return body.result;
}
Call this helper with the response from your sync request. Handle network errors and rejected responses in the caller, and validate the fields inside result for your integration before using them. Checking only response.ok or HTTP 200 would accept the application-error example above.
Outputs (what you get)
N/A
Outcomes
| Name | Description |
|---|---|
| Success | The response action completed. Inspect the response body for the application result. |
Requirements
- N/A