Skip to content
pushqdocs
Get started

The Tasks API is how you put work on a pushq queue and follow it through delivery. A task is one HTTP request that pushq will send to your endpoint, on time, at the queue’s rate, with retries. This page documents every task endpoint: enqueue a task, enqueue tasks in bulk, list and get tasks, run a task now, delete a task, and list its delivery attempts.

const task = await pq.createTask("emails", {
taskId: "welcome-user-42",
path: "/hooks/send-welcome",
jsonBody: { user_id: 42 },
delaySeconds: 3600,
});

The examples assume an SDK client named pq (and, in Go, a ctx), created as shown in install and configure an SDK. They use the hosted API at https://api.pushqueue.dev; self-hosted servers expose the same endpoints at their own URL. Parameter tables use the JSON field names (dispatch_deadline_seconds); the SDKs use their language’s casing for the same fields: camelCase in TypeScript and Java (dispatchDeadlineSeconds), snake_case in Python, PascalCase in Go and .NET.

Endpoint Writer API key Admin API key Dashboard roles
Enqueue, batch enqueue, run, delete yes yes member, admin
List, get, list attempts yes yes viewer, member, admin

A request without valid credentials gets 401 unauthenticated; a key or role without the permission gets 403 permission_denied.

Every endpoint that returns a task uses this shape.

{
"id": "welcome-user-42",
"queue": "emails",
"state": "pending",
"url": "/hooks/send-welcome",
"method": "POST",
"headers": { "Content-Type": "application/json" },
"body_base64": "eyJ1c2VyX2lkIjo0Mn0=",
"schedule_time": "2026-11-28T11:15:00.12Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 600,
"retry": { "max_attempts": 3 },
"dispatch_count": 1,
"response_count": 1,
"first_attempt_at": "2026-11-28T11:15:00.304Z",
"last_attempt": {
"at": "2026-11-28T11:15:00.304Z",
"status": 503,
"error": "non_2xx: upstream unavailable"
}
}
Field Type Description
id string Task ID: the task_id you sent, or a server-generated UUIDv7.
queue string Queue name.
state string pending (waiting for its time or a dispatch slot, including between retries), running (being delivered now), succeeded (got a 2xx) or failed (retries exhausted, or a task whose own headers can never be sent).
url string The absolute url, or the path as sent (resolved against the queue’s target.base_url at dispatch).
method string HTTP method stored on the task. A queue-level target.method overrides it at dispatch.
headers object Task headers. Only in the full view (and in create responses); omitted when empty.
body_base64 string Request body, base64-encoded. Only in the full view (and in create responses); omitted when empty.
schedule_time string (RFC 3339) When the task is (or was) due. Moves forward on each retry, and to “now” on a force-run.
created_at string (RFC 3339) When the task was created.
dispatch_deadline_seconds number How long pushq waits for a response on each attempt.
retry object The per-task retry override you sent (only the fields you set), not the effective policy. Omitted when there is none. Fields as in retry fields.
dispatch_count integer Attempts started so far.
response_count integer Attempts that got an HTTP response (any status).
first_attempt_at string (RFC 3339) When the first attempt started. Omitted before the first attempt.
finished_at string (RFC 3339) When the task succeeded or failed for good. Omitted while it is pending or running.
last_attempt.at string (RFC 3339) When the latest attempt started. last_attempt is omitted before the first attempt.
last_attempt.status integer HTTP status of the latest attempt. Omitted when no response arrived.
last_attempt.error string Error kind of the latest attempt, followed by up to 512 characters of detail (non_2xx: <response body>). Omitted on success.

POST /v1/queues/{queue}/tasks

Creates one task. pushq will send it as an HTTP request to url (or the queue’s target.base_url + path) at schedule_time, within the queue’s rate limits, and retry it on failure according to the queue’s retry policy merged with any per-task retry override. Use this for every unit of background work: send an email, call a webhook, run a job later.

Give the task a task_id when the same work might be enqueued twice (a retried request, a duplicate event): a second enqueue with the same ID in the same queue fails with 409 already_exists instead of creating a duplicate. That makes task_id your idempotency key. See deduplicate tasks with task IDs.

Tasks can be added to a paused queue (they wait until it’s resumed) but not to a disabled one.

Who can call it: writer or admin API key; dashboard member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram). The queue must exist.

Request body

Parameter Type Required Default Description
task_id string no server-generated UUIDv7 Your ID for the task, [A-Za-z0-9_-], 1–500 characters. Deduplicates within the queue (see below).
url string one of url/path — Absolute http or https URL to call, at most 2083 characters.
path string one of url/path — Path starting with /, appended to the queue’s target.base_url at dispatch time. The queue must have a target.base_url.
method string no POST GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS (case-insensitive).
headers object (string → string) no none Request headers. Names and values must be valid HTTP; Host, Content-Length, Transfer-Encoding, Connection, Keep-Alive, Upgrade, TE and Trailer are reserved. Total size at most 16 KiB (self-hosted default). Queue target.headers override these at dispatch.
json_body any JSON value no none Body to send as JSON. Sets Content-Type: application/json unless you set a Content-Type header. Can’t be combined with body_base64.
body_base64 string no none Raw body, standard base64. Without a Content-Type header it is sent as application/octet-stream. Can’t be combined with json_body.
schedule_time string (RFC 3339) no now When to send it. A time in the past means “now”. At most 1 year ahead (self-hosted default). Can’t be combined with delay_seconds.
delay_seconds number no 0 Send it this many seconds from now. At least 0; also limited by the 1-year schedule-ahead limit.
dispatch_deadline_seconds number no 600 How long to wait for a response on each attempt before it counts as a timeout. 15–1800.
retry object no queue’s policy Per-task override of the queue’s retry policy; set only the fields you want to change.
retry.max_attempts integer no queue’s -1 (unlimited) or at least 1, including the first attempt.
retry.max_retry_duration_seconds number no queue’s At least 0; 0 = unlimited. Measured from the first attempt.
retry.min_backoff_seconds number no queue’s At least 0.
retry.max_backoff_seconds number no queue’s At least min_backoff_seconds.
retry.max_doublings integer no queue’s 0–31.

A body (json_body or body_base64) is only allowed with POST, PUT or PATCH, and may be at most 1 MiB once decoded (self-hosted default). The JSON request itself may be at most twice that plus 64 KiB. Per-task retry values are checked against the server’s default retry policy when the task is created; the queue’s policy fills in the fields you leave out when the task runs. See retry backoff and max attempts.

How long a task ID stays taken. A task_id is reserved in its queue for as long as a task with that ID is stored: while it is pending or running, after it finishes until retention cleanup removes it (self-hosted defaults: 24 hours after success, 7 days after failure), and for the dedup window after you delete a task (self-hosted default: 1 hour). Purging the queue frees all IDs immediately. Limits on the hosted service may differ from these self-hosted defaults.

Example

The example at the top of this page enqueues a JSON task with a delay. This one calls an absolute URL with a raw body at a fixed time:

const task = await pq.createTask("emails", {
url: "https://api.example.com/hooks/digest",
method: "PUT",
headers: { "Content-Type": "text/plain" },
body: "weekly digest for user 42", // string or Uint8Array; the SDK base64-encodes it
scheduleTime: new Date("2026-12-01T09:00:00Z"),
dispatchDeadlineSeconds: 120,
retry: { maxAttempts: 3 },
});

The SDKs take the raw body and do the base64 encoding for you. In .NET, delay_seconds and dispatch_deadline_seconds are TimeSpan properties named Delay and DispatchDeadline, and the task type is PushqTask (to avoid clashing with System.Threading.Tasks.Task). In Python, a naive datetime for schedule_time is treated as UTC. Some SDKs catch conflicting fields before sending: the Java builder rejects url with path, a body with json_body, and schedule_time with delay_seconds; .NET rejects the last two; TypeScript and Python reject a body with json_body. Everything else is validated by the server.

Response

201 Created with the task object. The create response always includes headers and body_base64 when set:

{
"id": "0193b6f2-7c1e-7a3d-9f4e-2b8c5d1a6e90",
"queue": "emails",
"state": "pending",
"url": "https://api.example.com/hooks/digest",
"method": "PUT",
"headers": { "Content-Type": "text/plain" },
"body_base64": "d2Vla2x5IGRpZ2VzdCBmb3IgdXNlciA0Mg==",
"schedule_time": "2026-12-01T09:00:00Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 120,
"retry": { "max_attempts": 3 },
"dispatch_count": 0,
"response_count": 0
}

Field descriptions are in the task object.

Errors

Status Code When
400 invalid_argument Invalid JSON; bad task_id; both or neither of url/path; invalid URL; path not starting with /; method not allowed; invalid or reserved header; headers or body too large; invalid base64; body with a method that doesn’t allow one; both schedule_time and delay_seconds; schedule too far ahead; dispatch_deadline_seconds outside 15–1800; invalid retry values.
400 failed_precondition The task uses path but the queue has no target.base_url, or the queue is disabled.
401 unauthenticated No valid credentials.
403 permission_denied The key or role can’t write.
404 not_found The queue doesn’t exist.
409 already_exists A task with this task_id is already stored in the queue.
413 payload_too_large The request body is over the size limit.

See API error codes for the error format.

POST /v1/queues/{queue}/tasks:batch

Creates up to 500 tasks in one request. Use it for fan-out (one task per user, per row, per webhook subscriber) to cut round trips. The batch is not atomic: each item succeeds or fails on its own, and the response lists a result per item in request order. A duplicate task_id, including one repeated inside the same batch, fails only that item with already_exists. See bulk enqueue.

Who can call it: writer or admin API key; dashboard member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram). The queue must exist.

Request body

Parameter Type Required Default Description
tasks array yes — 1–500 task definitions.
tasks[].* object — — Each item takes exactly the fields of Enqueue a task: task_id, url, path, method, headers, json_body, body_base64, schedule_time, delay_seconds, dispatch_deadline_seconds, retry.*.

The whole request may be at most 8 MiB.

Example

const results = await pq.createTasks("emails", [
{ taskId: "welcome-user-42", path: "/hooks/send-welcome", jsonBody: { user_id: 42 } },
{ taskId: "welcome-user-43", path: "/hooks/send-welcome", jsonBody: { user_id: 43 } },
]);
for (const r of results) {
if (r.error) console.warn(`#${r.index}: ${r.error.code} ${r.error.detail}`);
else console.log(`#${r.index}: created ${r.task!.id}`);
}

The SDK method is createTasks / create_tasks / CreateTasks / CreateTasksAsync and returns the results array directly. In Python each item is a dict using create_task’s keyword names; unknown keys are silently ignored.

Response

200 OK, even when some items failed:

{
"results": [
{
"index": 0,
"task": {
"id": "welcome-user-42",
"queue": "emails",
"state": "pending",
"url": "/hooks/send-welcome",
"method": "POST",
"headers": { "Content-Type": "application/json" },
"body_base64": "eyJ1c2VyX2lkIjo0Mn0=",
"schedule_time": "2026-11-28T10:15:00.12Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 600,
"dispatch_count": 0,
"response_count": 0
}
},
{
"index": 1,
"error": { "code": "already_exists", "detail": "already exists" }
}
]
}
Field Type Description
results array One entry per input task, in request order.
results[].index integer Position of the task in the request (0-based).
results[].task task object The created task. Present only on success.
results[].error.code string Present only on failure: invalid_argument, already_exists, not_found, failed_precondition or internal.
results[].error.detail string Human-readable reason for the failure.

Errors

These fail the whole request; per-item failures are reported in results instead.

Status Code When
400 invalid_argument Invalid JSON, tasks empty, or more than 500 tasks.
401 unauthenticated No valid credentials.
403 permission_denied The key or role can’t write.
404 not_found The queue doesn’t exist.
413 payload_too_large Request body over 8 MiB.

GET /v1/queues/{queue}/tasks

Lists a queue’s tasks, newest first, one page at a time. Filter by state to find failed tasks to inspect or retry, or by id_prefix to find a group of related tasks (for example everything for one user if your IDs start with the user ID). Deleted and purged tasks are not listed; finished tasks are listed until retention cleanup removes them.

Who can call it: writer or admin API key; dashboard viewer, member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram).

Query parameters

Parameter Type Required Default Description
state string no all pending, running, succeeded or failed.
id_prefix string no none Only tasks whose ID starts with this.
view string no basic basic omits headers and body_base64; full includes them.
page_size integer no 100 Tasks per page. Values above 1000 are capped at 1000; 0 or less means 100.
page_token string no none next_page_token from the previous response.

Example

const page = await pq.listTasks("emails", { state: "failed", idPrefix: "welcome-", pageSize: 50 });
for (const t of page.items) console.log(t.id, t.lastAttempt?.status, t.lastAttempt?.error);
// page.nextPageToken -> pass as pageToken for the next page

Response

200 OK:

{
"tasks": [
{
"id": "welcome-user-43",
"queue": "emails",
"state": "failed",
"url": "/hooks/send-welcome",
"method": "POST",
"schedule_time": "2026-11-28T10:42:51.004Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 600,
"retry": { "max_attempts": 3 },
"dispatch_count": 3,
"response_count": 3,
"first_attempt_at": "2026-11-28T10:15:00.31Z",
"finished_at": "2026-11-28T10:42:51.88Z",
"last_attempt": {
"at": "2026-11-28T10:42:51.004Z",
"status": 500,
"error": "non_2xx: template not found"
}
}
],
"next_page_token": "MTI4Nzc"
}
Field Type Description
tasks array of task objects This page, newest first. Empty array when nothing matches.
next_page_token string Pass as page_token to get the next page. Omitted on the last page.

The SDKs return a page object: items / nextPageToken in TypeScript, items / next_page_token in Python, getTasks() / getNextPageToken() in Java, Items / NextPageToken in .NET; Go returns the slice and the next token separately.

Errors

Status Code When
400 invalid_argument Unknown state, or page_size not an integer.
400 failed_precondition page_token is malformed.
401 unauthenticated No valid credentials.
403 permission_denied The caller has no read permission.
404 not_found The queue doesn’t exist.

GET /v1/queues/{queue}/tasks/{taskID}

Returns one task’s current state, schedule and last attempt. Use it to check whether a specific job ran, or (with view=full) to see exactly what will be sent. Deleted and purged tasks return 404.

Who can call it: writer or admin API key; dashboard viewer, member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram).
taskID string yes — The task’s ID.

Query parameters

Parameter Type Required Default Description
view string no basic basic omits headers and body_base64; full includes them.

Example

const task = await pq.getTask("emails", "welcome-user-42");
const full = await pq.getTask("emails", "welcome-user-42", { view: "full" });
const body = full.body ? new TextDecoder().decode(full.body) : undefined; // Uint8Array

Go and Java get the full view from a separate method (GetTaskFull, getTaskFull) and return the body as the base64 string; TypeScript, Python and .NET decode it into bytes for you.

Response

200 OK with the task object (here with view=full):

{
"id": "welcome-user-42",
"queue": "emails",
"state": "succeeded",
"url": "/hooks/send-welcome",
"method": "POST",
"headers": { "Content-Type": "application/json" },
"body_base64": "eyJ1c2VyX2lkIjo0Mn0=",
"schedule_time": "2026-11-28T11:15:00.12Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 600,
"dispatch_count": 1,
"response_count": 1,
"first_attempt_at": "2026-11-28T11:15:00.304Z",
"finished_at": "2026-11-28T11:15:00.511Z",
"last_attempt": { "at": "2026-11-28T11:15:00.304Z", "status": 200 }
}

Errors

Status Code When
401 unauthenticated No valid credentials.
403 permission_denied The caller has no read permission.
404 not_found No such task (or it was deleted or purged), or no such queue.

DELETE /v1/queues/{queue}/tasks/{taskID}

Cancels a task. A pending task will never be sent; if it is being delivered right now, the delivery’s result is discarded. You can also delete finished tasks. Use it to cancel scheduled work that is no longer needed, such as a reminder for an order that was already paid. The task ID stays reserved for the dedup window (1 hour by default on self-hosted servers), so re-enqueueing the same ID right away fails with already_exists. See schedule and cancel tasks.

Who can call it: writer or admin API key; dashboard member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram).
taskID string yes — The task’s ID.

Example

await pq.deleteTask("emails", "welcome-user-42");

Response

204 No Content with an empty body.

Errors

Status Code When
401 unauthenticated No valid credentials.
403 permission_denied The key or role can’t write.
404 not_found No such task (or already deleted or purged), or no such queue.

POST /v1/queues/{queue}/tasks/{taskID}:run

Dispatches a pending task immediately: its schedule_time is set to now and it is sent right away, ignoring the queue’s rate limits and its paused state. Use it to test a delivery, to skip the wait on a delayed or backing-off task, or to push one urgent task through a paused queue. Only pending tasks can be run.

Who can call it: writer or admin API key; dashboard member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram).
taskID string yes — The task’s ID.

No request body.

Example

const task = await pq.runTask("emails", "welcome-user-42");

Response

200 OK with the task object in the full view, still pending with schedule_time set to now (the dispatch happens right after the response):

{
"id": "welcome-user-42",
"queue": "emails",
"state": "pending",
"url": "/hooks/send-welcome",
"method": "POST",
"headers": { "Content-Type": "application/json" },
"body_base64": "eyJ1c2VyX2lkIjo0Mn0=",
"schedule_time": "2026-11-28T10:20:31.007Z",
"created_at": "2026-11-28T10:15:00.12Z",
"dispatch_deadline_seconds": 600,
"dispatch_count": 0,
"response_count": 0
}

Errors

Status Code When
400 failed_precondition The task is being delivered right now, or the queue is disabled.
401 unauthenticated No valid credentials.
403 permission_denied The key or role can’t write.
404 not_found No such task or queue, or the task already succeeded, failed, was deleted or was purged.

GET /v1/queues/{queue}/tasks/{taskID}/attempts

Returns the task’s delivery attempts, newest first (up to the 1000 most recent), with the status code, error kind, a snippet of the response body and the duration of each. Use it to debug why a task is failing or retrying. Attempts are kept as long as the task is.

Who can call it: writer or admin API key; dashboard viewer, member or admin.

Path parameters

Parameter Type Required Default Description
queue string yes — Queue name, URL-encoded as one segment (user%2Finstagram).
taskID string yes — The task’s ID.

Example

const attempts = await pq.listAttempts("emails", "welcome-user-42");
for (const a of attempts) console.log(a.number, a.responseStatus ?? a.errorKind, a.durationMs);

The SDKs return the list of attempts directly (no page object).

Response

200 OK:

{
"attempts": [
{
"number": 2,
"dispatch_time": "2026-11-28T11:15:02.41Z",
"response_time": "2026-11-28T11:15:02.598Z",
"response_status": 200,
"duration_ms": 188
},
{
"number": 1,
"dispatch_time": "2026-11-28T11:15:00.304Z",
"response_time": "2026-11-28T11:15:00.511Z",
"response_status": 503,
"error_kind": "non_2xx",
"error_snippet": "upstream unavailable",
"duration_ms": 207
}
]
}
Field Type Description
attempts array Attempts, newest first. Empty array before the first attempt.
attempts[].number integer Attempt number, starting at 1.
attempts[].dispatch_time string (RFC 3339) When the request was sent.
attempts[].response_time string (RFC 3339) When the response arrived. Omitted when there was no response.
attempts[].response_status integer HTTP status code. Omitted when there was no response.
attempts[].error_kind string Why the attempt failed: non_2xx, timeout, connect, dns, tls, config (the request couldn’t be built, e.g. relative path with no target.base_url) or lease_lost (the worker stopped mid-delivery). Omitted on success.
attempts[].error_snippet string Up to 4 KiB of the response body for non_2xx, or the error message otherwise. Omitted when empty.
attempts[].duration_ms integer How long the attempt took, in milliseconds.

Errors

Status Code When
401 unauthenticated No valid credentials.
403 permission_denied The caller has no read permission.
404 not_found No such task (or it was deleted or purged), or no such queue.