Skip to content

API v2 synchronous writes and long-running operations

Most writes complete before the response returns, so your client can use the returned resource immediately. When the main change takes longer than the wait window, the API hands back an operation you can poll or receive by webhook instead of guessing whether the write happened.

How a synchronous write completes

Background processing is hidden for typical writes. The request first validates the key scopes and any on-behalf-of header, checks an idempotency key if one was sent, submits the change, waits for the decisive step to report, then reads the resource back for the response. That decisive step is the part that determines success, such as saving a leave request. Later work, including calendar synchronisation and Slack or email notifications, runs after the response and is not part of the wait.

Because the resource is read immediately after the decisive step, follow-up fields may not be present yet. Read the resource again shortly afterwards if those fields matter.

Decision checklist before treating a write as done:

  • Was the response 201, 200, or 204, or was it 202?
  • If 202, did you keep the operation URL and idempotency key?
  • If polling, are you branching on status and, for failures, on error.code?
  • If the status became UNKNOWN, did you read the resource before retrying?
  • Did you retry only with the same key and same body?

Responses inside the wait window, and the 202 fallback

A created resource returns 201 with the resource in data. An update or an action such as approve or cancel returns 200 with the resource in data. A deletion normally returns 204 with no content, except deleting a leave or TOIL request, which returns 200 with the deleted request. A rejected change returns the relevant error status from the error catalog, for example 422 for a blackout-period conflict, with an error body.

If the decisive step has not reported within 20 seconds of the request arriving, the API stops waiting and returns 202. The response contains an operation with an identifier beginning pa_, a status, and a URL for that operation. The same 202 shape is used when the change succeeded but the resource could not yet be read back; in that case the status is already SUCCEEDED. In either case, 202 signals progress, not failure, and the change continues without further action from you.

Polling, statuses, access, and webhooks

Use the operation URL with the same bearer key that submitted the write. The returned operation describes the identifier, its status, the public action such as leaves.approve, submission and completion times in ISO 8601, the user the write was made as, and, when known, the affected resource with its type, identifier, and URL. A failure adds error details matching the error catalog. Completion time is present only once the operation reaches SUCCEEDED or FAILED.

Poll every few seconds and slow down if it remains PENDING. Polling uses your rate-limit allowance. Stop at UNKNOWN, which appears when no result arrived within 15 minutes: the change may or may not have been applied, so inspect the resource before retrying. A later result can still move the status to SUCCEEDED or FAILED. Retrying with the same idempotency key cannot apply the change twice.

Only the submitting key can read an operation, and no additional scope is required. Any other key, or an operation older than the retention period, returns 404 RESOURCE_NOT_FOUND. Operations are retained for 90 days. If polling is inconvenient, subscribe a webhook to operation.completed for success or operation.failed for failure.

Client guidance for safe retries

Send an idempotency key on every write so a client-side timeout is safe to retry. Never resubmit a 202 with a new key or no key, because the change is already running and could be applied twice; reuse the same key and body to get the same operation back. Treat 202 as in progress rather than an error, and branch on status, then on error.code for failures. Set the HTTP client timeout above 20 seconds, with 30 seconds as a practical setting, so the client receives the 202 instead of timing out first.

Example flow: submit a leave request with an idempotency key and a client timeout above 20 seconds. If the decisive step is slow, receive a 202 with a PENDING operation. Poll the operation URL every few seconds. On SUCCEEDED, read the resource from resource.url. On FAILED, act on error.code. On UNKNOWN, read the resource first, then retry only with the original key and body.

Write responses at a glance
Outcome within wait limitResponse
Created201 Created with { "data": <resource> }
Updated, or an action such as approve or cancel200 OK with { "data": <resource> }
Deleted204 No Content, except leave or TOIL deletion
FailedError-catalog status, for example 422 LEAVE_BLACKOUT_PERIOD, with { "error": ... }
Not finished within 20 seconds202 Accepted with an operation to poll

Deleting a leave or TOIL request returns 200 OK with the deleted request instead of 204.

Operation fields
FieldMeaning
idOperation ID, always starts with pa_
statusPENDING, SUCCEEDED, FAILED, or UNKNOWN
actionPublic action, for example leaves.approve
createdAtWhen the write was submitted (ISO 8601)
completedAtWhen the operation reached SUCCEEDED or FAILED
actingAsUserIdKey owner, or the user in X-On-Behalf-Of
resourceAffected resource with type, id, and url
errorOnly when FAILED: code, name, description, and optional details

completedAt is absent while PENDING or UNKNOWN; resource is absent when not known up front; error appears only when FAILED.

Operation statuses
StatusWhat to do
PENDINGChange still running; poll again, backing off if it stays pending
SUCCEEDEDMain part applied; read the resource from resource.url
FAILEDChange rejected; inspect error.code
UNKNOWNNo result within 15 minutes; read the resource before retrying

UNKNOWN can still change to SUCCEEDED or FAILED if a result arrives later.

Frequently asked questions

Does 202 Accepted mean my write failed?

A 202 means the write is still in progress and will finish on its own; it is not a failure. Poll the operation URL, or use a webhook, and branch on its status.

Who can read an operation?

Only the key that submitted the write can read it, with no extra scope. Other keys, and operations past retention, return 404 RESOURCE_NOT_FOUND.

How long are operations retained?

Operations are kept for 90 days.

{
  "operation": {
    "id": "pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91",
    "status": "PENDING",
    "url": "/v2/operations/pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91"
  }
}
curl $API_BASE_URL/v2/operations/pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91 \
  -H "Authorization: Bearer vt_live_your-secret"
{
  "data": {
    "id": "pa_3f6e2a1c-8b4d-4c1e-9a7f-5d2b0c6e8f91",
    "status": "SUCCEEDED",
    "action": "leaves.request",
    "createdAt": "2026-09-24T09:15:02.114Z",
    "completedAt": "2026-09-24T09:15:24.870Z",
    "actingAsUserId": "...",
    "resource": {
      "type": "leaves",
      "id": "...",
      "url": "/v2/leaves/..."
    }
  }
}