# REST API overview

> How the pushq REST API works: base URL, API key auth, URL-encoded queue names, pagination, errors and idempotency, plus every endpoint.

Source: https://pushqueue.dev/docs/reference/api/

Everything pushq does is available over a JSON HTTP API. The SDKs and the dashboard use the same API. This page covers the conventions every endpoint shares and lists all endpoints; each group links to its detailed reference.

Use the API directly when there's no SDK for your language, from shell scripts, or to debug what an SDK sends.

- Interactive reference (Swagger UI): https://api.pushqueue.dev/docs
- OpenAPI document: https://api.pushqueue.dev/openapi.json

A self-hosted server serves the same two pages at `/docs` and `/openapi.json`, generated from its own routes. To get the document without running a server, use `pushq openapi > openapi.json`.

## API base URL

| Server | Base URL |
|---|---|
| Hosted | `https://api.pushqueue.dev` |
| Self-hosted | Your server, e.g. `http://localhost:8080` or `https://pushq.example.com` |

API endpoints live under `/v1`. Health, metrics and documentation endpoints (`/healthz`, `/readyz`, `/metrics`, `/docs`, `/openapi.json`) sit at the root.

## Authenticate with an API key

Send an API key as a bearer token:

```bash
curl https://api.pushqueue.dev/v1/queues/emails \
  -H "Authorization: Bearer $PUSHQ_API_KEY"
```

Keys look like `pq_...`. Create them in the dashboard under **Settings → API keys**, or, when self-hosting, in the server config. See [API keys](https://pushqueue.dev/docs/guides/api-keys/) for roles and rotation.

A missing or unknown key returns `401 unauthenticated`. A valid key whose role doesn't allow the call returns `403 permission_denied`.

The dashboard authenticates with a session cookie instead. Requests that change something with the cookie must also send `X-Requested-With: pushq`, which blocks cross-site request forgery. Requests with an `Authorization` header don't need it.

A `pushq dev` server, or a fresh self-hosted server before its first admin account exists, accepts requests without a key.

### Who can call what

The endpoint tables use these access levels:

| Access | API keys | Dashboard users |
|---|---|---|
| Public | No credentials needed | |
| Read | `admin`, `writer` | `admin`, `member`, `viewer` |
| Write | `admin`, `writer` | `admin`, `member` |
| List | `admin` | `admin`, `member`, `viewer` |
| Delete queue | `admin` | `admin`, `member` |
| Manage | `admin` | `admin` |
| Signed-in user | Not allowed (`401`) | Any role, with a session cookie |

A `writer` key works with queues it knows by name: it can create, change, pause, resume and purge queues and enqueue, run and delete tasks, but it can't list all queues or delete a queue.

## Request and response format

- Request and response bodies are JSON. Send `Content-Type: application/json` with a body.
- Field names are `snake_case`: `rate_limits.max_dispatches_per_second`, `delay_seconds`. The SDKs use their language's casing.
- Timestamps are RFC 3339 strings in UTC, e.g. `2026-12-01T17:00:00Z`.
- Durations are numbers of seconds and may be fractional: `"min_backoff_seconds": 0.1`.
- Operations that aren't plain CRUD use a colon suffix on the resource, Google API style: `POST /v1/queues/emails:pause`, `POST /v1/queues/emails/tasks/welcome-user-42:run`.
- Deletes answer `204 No Content`. `:purge` answers `202 Accepted`.

Request bodies have size limits: 256 KiB for queue bodies, 8 MiB for a batch, and for a single task twice `limits.max_body_bytes` plus 64 KiB (the body is base64-encoded inside the JSON). A larger request fails with `413 payload_too_large`. The decoded task body itself must fit in `limits.max_body_bytes` (default 1 MiB).

## URL-encode queue names

Queue names can contain `/` to form folders, such as `user/instagram`. In a URL path the whole name is **one** segment, so encode the slash as `%2F`:

```bash
curl -X POST https://api.pushqueue.dev/v1/queues/user%2Finstagram/tasks \
  -H "Authorization: Bearer $PUSHQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"path": "/hooks/post"}'
```

An unencoded slash produces a different path and returns `404 not_found` with a hint to encode it. Query parameters take the name as-is: `GET /v1/queues?name_prefix=user/` lists the folder. The SDKs encode queue names for you. If you run a reverse proxy, make sure it doesn't decode `%2F`; see [reverse proxy setup](https://pushqueue.dev/docs/self-hosting/deploy/#put-pushq-behind-a-reverse-proxy).

Valid queue names are 1 to 200 characters of `/`-separated segments, each matching `[a-z0-9][a-z0-9-]*`. Task IDs match `[A-Za-z0-9_-]{1,500}`.

## Paginate list results

`GET /v1/queues` and `GET /v1/queues/{queue}/tasks` return one page at a time:

| Query parameter | Description |
|---|---|
| `page_size` | Items per page. Default 100, maximum 1000 (larger values are capped). |
| `page_token` | The `next_page_token` from the previous response. |

The response holds the items (`queues` or `tasks`) and a `next_page_token`. When `next_page_token` is missing, you have the last page. Keep your other filters (`state`, `id_prefix`, `name_prefix`) the same while you page. A malformed token returns `400 failed_precondition`.


**TypeScript**

```ts
let pageToken: string | undefined;
do {
  const page = await pq.listTasks("emails", { state: "failed", pageSize: 500, pageToken });
  for (const task of page.items) console.log(task.id);
  pageToken = page.nextPageToken;
} while (pageToken);
```

**Python**

```python
page_token = None
while True:
    page = pq.list_tasks("emails", state="failed", page_size=500, page_token=page_token)
    for task in page.items:
        print(task.id)
    page_token = page.next_page_token
    if not page_token:
        break
```

**Go**

```go
token := ""
for {
	tasks, next, err := pq.ListTasks(ctx, "emails", pushq.ListTasksParams{State: "failed", PageSize: 500, PageToken: token})
	if err != nil {
		return err
	}
	for _, t := range tasks {
		fmt.Println(t.ID)
	}
	if next == "" {
		break
	}
	token = next
}
```

**Java**

```java
String token = null;
do {
  TaskPage page = pq.listTasks("emails", ListTasksParams.builder()
      .state("failed").pageSize(500).pageToken(token).build());
  for (Task task : page.getTasks()) System.out.println(task.getId());
  token = page.getNextPageToken();
} while (token != null && !token.isEmpty());
```

**.NET**

```csharp
string? token = null;
do
{
    var page = await pq.ListTasksAsync("emails", new ListTasksOptions
    {
        State = TaskState.Failed, PageSize = 500, PageToken = token,
    });
    foreach (var task in page.Items) Console.WriteLine(task.Id);
    token = page.NextPageToken;
} while (!string.IsNullOrEmpty(token));
```

**curl**

```bash
token=""
while :; do
  resp=$(curl -s "https://api.pushqueue.dev/v1/queues/emails/tasks?state=failed&page_size=500&page_token=$token" \
    -H "Authorization: Bearer $PUSHQ_API_KEY")
  echo "$resp" | jq -r '.tasks[].id'
  token=$(echo "$resp" | jq -r '.next_page_token // empty')
  [ -z "$token" ] && break
done
```

Tasks are listed newest first.

## Error responses

Every error is an [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem+json body with a stable machine-readable `code`:

```json
{
  "type": "about:blank",
  "title": "Not Found",
  "status": 404,
  "code": "not_found",
  "detail": "not found",
  "instance": "/v1/queues/emails"
}
```

Branch on `code`, not on `detail`. See [API error codes](https://pushqueue.dev/docs/reference/errors/) for every code and how to handle it.

## Idempotency and safe retries

There is no `Idempotency-Key` header. Instead:

- **Queue upserts** (`PUT /v1/queues/{queue}`) are idempotent: send the same config as often as you like. The response answers `201` when it created the queue and `200` otherwise, with an `X-Pushq-Result` header of `created`, `updated` or `unchanged`. An upsert never changes whether the queue is running or paused.
- **Task creation** is deduplicated by `task_id`. If you retry an enqueue after a timeout or network error with the same `task_id`, a `409 already_exists` means the first request went through. The ID stays reserved for the server's dedup window (1 hour by default) after the task finishes or is deleted. Without a `task_id` the server generates one, and a retried request can create a duplicate task.
- **Batch enqueue** (`POST /v1/queues/{queue}/tasks:batch`) is not atomic. It answers `200` with one result per task, in request order; each result holds either the created `task` or an `error` with a `code` and `detail`. Retry only the failed items, and give tasks IDs so retries are safe.

Retry requests that fail with `5xx` or a network error, with backoff. Don't retry `4xx` errors without changing the request, except `429 rate_limited`.

## API endpoints

### Queue endpoints

Details: [Queues reference](https://pushqueue.dev/docs/reference/rest/queues/).

| Method | Path | Summary | Access |
|---|---|---|---|
| `POST` | `/v1/queues` | Create a queue (fails with `already_exists` if the name is taken) | Write |
| `PUT` | `/v1/queues/{queue}` | Create or replace a queue's configuration | Write |
| `GET` | `/v1/queues/{queue}` | Get a queue | Read |
| `PATCH` | `/v1/queues/{queue}` | Update some of a queue's settings, including `state` | Write |
| `DELETE` | `/v1/queues/{queue}` | Delete a queue and all its tasks | Delete queue |
| `GET` | `/v1/queues` | List queues (`name_prefix`, `page_size`, `page_token`) | List |
| `POST` | `/v1/queues/{queue}:pause` | Pause dispatching | Write |
| `POST` | `/v1/queues/{queue}:resume` | Resume dispatching | Write |
| `POST` | `/v1/queues/{queue}:purge` | Delete every task created up to now | Write |
| `GET` | `/v1/queues/{queue}/stats` | Live queue statistics (`id_prefix`) | Read |

### Task endpoints

Details: [Tasks reference](https://pushqueue.dev/docs/reference/rest/tasks/).

| Method | Path | Summary | Access |
|---|---|---|---|
| `POST` | `/v1/queues/{queue}/tasks` | Enqueue a task | Write |
| `POST` | `/v1/queues/{queue}/tasks:batch` | Enqueue up to 500 tasks | Write |
| `GET` | `/v1/queues/{queue}/tasks` | List tasks, newest first (`state`, `id_prefix`, `view`, `page_size`, `page_token`) | Read |
| `GET` | `/v1/queues/{queue}/tasks/{taskID}` | Get a task (`view=full` includes headers and body) | Read |
| `DELETE` | `/v1/queues/{queue}/tasks/{taskID}` | Delete a task | Write |
| `POST` | `/v1/queues/{queue}/tasks/{taskID}:run` | Dispatch a task now, bypassing rate limits and the paused state | Write |
| `GET` | `/v1/queues/{queue}/tasks/{taskID}/attempts` | A task's delivery attempts, newest first | Read |

### API key endpoints

Details: [API keys reference](https://pushqueue.dev/docs/reference/rest/api-keys/).

| Method | Path | Summary | Access |
|---|---|---|---|
| `GET` | `/v1/api-keys` | List API keys | Manage |
| `POST` | `/v1/api-keys` | Create an API key (the secret is returned once) | Manage |
| `DELETE` | `/v1/api-keys/{id}` | Revoke an API key | Manage |

### Team and user endpoints

Details: [Teams and users reference](https://pushqueue.dev/docs/reference/rest/teams-and-users/). Endpoints marked SaaS exist only on servers in [SaaS mode](https://pushqueue.dev/docs/self-hosting/saas-mode/), including the hosted service; those marked self-hosted exist only without it.

| Method | Path | Summary | Access |
|---|---|---|---|
| `PATCH` | `/v1/me` | Change your name | Signed-in user |
| `POST` | `/v1/me/password` | Change your password (self-hosted) | Signed-in user |
| `GET` | `/v1/teams` | Your teams (SaaS) | Signed-in user |
| `POST` | `/v1/teams` | Create a team (SaaS) | Signed-in user |
| `POST` | `/v1/teams/{id}:switch` | Switch your session to another of your teams (SaaS) | Signed-in user |
| `PATCH` | `/v1/teams/current` | Rename the current team (SaaS) | Manage |
| `GET` | `/v1/users` | List members | Manage |
| `PATCH` | `/v1/users/{id}` | Change a member's role | Manage |
| `DELETE` | `/v1/users/{id}` | Remove a member | Manage |
| `POST` | `/v1/users/{id}/reset-link` | Create a password-reset link (self-hosted) | Manage |
| `GET` | `/v1/invites` | Pending invites | Manage |
| `POST` | `/v1/invites` | Invite someone | Manage |
| `DELETE` | `/v1/invites/{id}` | Revoke an invite | Manage |

### Sign-in endpoints

Details: [Sign-in reference](https://pushqueue.dev/docs/reference/rest/auth/). These endpoints power the dashboard's sign-in pages. You don't need them to use queues and tasks.

| Method | Path | Summary | Access |
|---|---|---|---|
| `GET` | `/v1/auth/session` | Who am I, and how does this server sign people in? | Public |
| `POST` | `/v1/auth/setup` | Create the first admin account (self-hosted) | Public |
| `POST` | `/v1/auth/login` | Sign in with email and password (self-hosted) | Public |
| `POST` | `/v1/auth/logout` | Sign out | Public |
| `GET` | `/v1/auth/invites/{token}` | Look up an invite or password-reset link (self-hosted) | Public |
| `POST` | `/v1/auth/invites/{token}:accept` | Accept an invite or reset link (self-hosted) | Public |
| `POST` | `/v1/auth/email-code` | Email a 6-digit sign-in code (SaaS) | Public |
| `POST` | `/v1/auth/email-code:verify` | Sign in with the emailed code (SaaS) | Public |
| `GET` | `/v1/auth/email-verification` | Is a sign-in waiting for an email verification code? (SaaS) | Public |
| `POST` | `/v1/auth/email-verification` | Finish a sign-in with the emailed verification code (SaaS) | Public |
| `GET` | `/v1/auth/workos/login` | Start signing in with GitHub (SaaS) | Public |
| `GET` | `/v1/auth/workos/callback` | Where GitHub sign-in returns (SaaS) | Public |

### System endpoints

Details: [System reference](https://pushqueue.dev/docs/reference/rest/system/).

| Method | Path | Summary | Access |
|---|---|---|---|
| `GET` | `/healthz` | Liveness check (`ok`) | Public |
| `GET` | `/readyz` | Readiness check; reports the dispatcher role | Public |
| `GET` | `/metrics` | Prometheus metrics | Public by default; otherwise List (in SaaS mode, only the operator's config-file keys) |
| `GET` | `/openapi.json` | The OpenAPI document | Public |
| `GET` | `/docs` | Interactive API docs (Swagger UI) | Public |
| `GET` | `/v1/version` | Server version, commit and database dialect | Read |

## Read more

- [API error codes](https://pushqueue.dev/docs/reference/errors/): every `code` and how to handle it.
- [Install & configure an SDK](https://pushqueue.dev/docs/getting-started/sdks/): typed clients for TypeScript, Python, Go, Java and .NET.
- [API keys](https://pushqueue.dev/docs/guides/api-keys/): create, scope and revoke keys.
- [Queues](https://pushqueue.dev/docs/concepts/queues/) and [tasks](https://pushqueue.dev/docs/concepts/tasks/): what the fields mean.
