Check Background Jobs
Monitor the status of asynchronous operations such as role assignments, cascade knowledge deletion, taxonomy publishing, and other workflow-backed operations. When an endpoint runs asynchronously, it returns a workflowId — pass it here to track progress.
Endpoint
POST /v1/workspaces/{workspaceId}/background-jobsRequest
Before you run the following snippets, see the API Key Authentication section on the Authentication page. From there, follow Step 1: Generate Access Token to get an access token. Run that code first, in the same shell session or script as the following snippets. The snippets also rely on the environment variables SHARELY_API_URL, SHARELY_API_KEY, SHARELY_WORKSPACE_ID, and SHARELY_ORGANIZATION_ID, which are described in the Complete Authentication Example.
curl -X POST \
"$SHARELY_API_URL/v1/workspaces/$SHARELY_WORKSPACE_ID/background-jobs" \
-H "Authorization: Bearer $SHARELY_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-H "organizationid: $SHARELY_ORGANIZATION_ID" \
-d '{
"jobIds": ["workflow-id-1", "workflow-id-2"]
}'Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string (UUID) | Yes | The unique identifier of the workspace |
Headers
| Header | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Bearer token with access token |
organizationid | string (UUID) | Yes | Your organization ID |
Content-Type | string | Yes | Must be application/json |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
jobIds | array of strings | No | Workflow IDs to check (as returned by async endpoints). Omit to check all background jobs recorded for the workspace |
Response
Success Response (200 OK)
Returns an array — one entry per matched job. Returns [] if no jobs match.
[
{
"workflowId": "workflow-id-1",
"status": { "code": 2, "name": "COMPLETED" },
"runId": "0190a1b2-c3d4-..."
},
{
"workflowId": "workflow-id-2",
"status": { "code": 1, "name": "RUNNING" },
"runId": "0190a1b2-e5f6-..."
}
]Response Fields
| Field | Type | Description |
|---|---|---|
workflowId | string | The workflow ID you passed in (or that the async endpoint returned) |
status | object | Workflow execution status |
status.name | string | One of RUNNING, COMPLETED, FAILED, CANCELLED, TERMINATED, TIMED_OUT, CONTINUED_AS_NEW |
status.code | number | Numeric status code corresponding to status.name |
runId | string | The underlying workflow run identifier (useful when contacting support) |
Job Statuses
- RUNNING — the job is currently being processed
- COMPLETED — the job finished successfully; verify the resulting resource via its own GET endpoint
- FAILED / TERMINATED / TIMED_OUT — the job did not complete; retry the originating operation or contact support with the
workflowIdandrunId - CANCELLED — the job was cancelled before completion
Polling for Completion
The following snippets poll the endpoint with exponential backoff (up to 30 seconds between attempts) until every job reaches a terminal state. They use the same environment variables and access token as the previous snippets.
for attempt in $(seq 0 29); do
jobs=$(curl -s -X POST \
"$SHARELY_API_URL/v1/workspaces/$SHARELY_WORKSPACE_ID/background-jobs" \
-H "Authorization: Bearer $SHARELY_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-H "organizationid: $SHARELY_ORGANIZATION_ID" \
-d '{"jobIds": ["workflow-id-1", "workflow-id-2"]}')
# Count jobs that have not reached a terminal state
pending=$(jq '[.[] | select(.status.name | IN("COMPLETED", "FAILED", "CANCELLED", "TERMINATED", "TIMED_OUT") | not)] | length' <<< "$jobs")
if [ "$pending" -eq 0 ]; then
echo "$jobs"
break
fi
# Exponential backoff, capped at 30 seconds
wait=$(( 2 ** attempt > 30 ? 30 : 2 ** attempt ))
sleep "$wait"
doneBest Practices
- Poll Interval: Start with 1-2 second intervals, increase with exponential backoff
- Timeout: Set a reasonable timeout (30-60 seconds for most operations)
- Batch Checking: Check multiple workflow IDs in a single request
- Verify outcomes: The status tells you the workflow finished, not what it produced — confirm via the resource's own GET endpoint
- Keep IDs for support: Log
workflowIdandrunIdfor failed jobs
Related Endpoints
- Assign Knowledge to Roles - Returns workflow IDs
- Delete Role - Returns workflow IDs
- Delete Knowledge - May return workflow IDs