# API Reference

Base URL: `https://api.zeplo.io`

All endpoints require authentication via `Authorization: Bearer <token>` header. See [Authentication](/docs/authentication).

---

## Queues

### List queues
`GET /workspaces/:workspaceId/queues/`

Returns all queues in the workspace.

### Create queue
`POST /workspaces/:workspaceId/queues/`

```json
{
  "name": "string (required)",
  "type": "standard | fifo"
}
```

### Get queue
`GET /workspaces/:workspaceId/queues/:queueId/`

Returns queue details including metrics (request count, success rate, error rate, avg response time).

### Update queue
`PATCH /workspaces/:workspaceId/queues/:queueId/`

```json
{
  "name": "string",
  "status": "active | paused"
}
```

### Delete queue
`DELETE /workspaces/:workspaceId/queues/:queueId/`

---

## Requests

### Enqueue request (public)
`POST /queues/enqueue`

This is the primary endpoint for adding work to a queue. Zeplo resolves the destination queue from the bearer token.

```json
{
  "method": "GET | POST | PUT | PATCH | DELETE",
  "url": "string (required)",
  "headers": {},
  "body": "string",
  "delay": 0,
  "retries": 3,
  "requestId": "string"
}
```

**Legacy v1 compatibility headers supported:**
- `X-Zeplo-Delay`
- `X-Zeplo-Delay-Until`
- `X-Zeplo-Retry`
- `X-Zeplo-Interval`
- `X-Zeplo-Cron`
- `X-Zeplo-Timezone`

**Precedence:**
- body `retries` overrides `X-Zeplo-Retry`
- body `delay` overrides delay headers
- `X-Zeplo-Interval` overrides `X-Zeplo-Cron` when both are present

**Response (202) — request queued or delayed:**

```json
{
  "requestId": "req_xyz789",
  "status": "queued|scheduled",
  "queuedAt": "2026-03-12T19:00:00Z"
}
```

**Response (202) — recurring schedule created via legacy headers:**

```json
{
  "scheduleId": "sched_xyz789",
  "status": "scheduled",
  "type": "interval|cron",
  "nextRun": "2026-03-12T19:05:00Z",
  "createdAt": "2026-03-12T19:00:00Z"
}
```

**Compatibility route:**
`POST /queues/:queueId/enqueue`

Supported for explicit queue targeting, but not the default path for new integrations.

### Create request (dashboard)
`POST /workspaces/:workspaceId/queues/:queueId/requests`

Same as enqueue but scoped to a workspace. Used by the dashboard.

### Get request
`GET /workspaces/:workspaceId/requests/:requestId`

Returns full request details including response data and timeline.

### List requests (queue logs)
`GET /workspaces/:workspaceId/queues/:queueId/logs/`

Returns paginated request history for a queue. Supports filtering by status.

---

## Schedules

### List schedules
`GET /workspaces/:workspaceId/schedules/`

### Create schedule
`POST /workspaces/:workspaceId/schedules/`

```json
{
  "name": "string (required)",
  "queueId": "string (required)",
  "schedule": "string (required, cron expression)",
  "requestTemplate": {
    "method": "POST",
    "url": "string (required)",
    "headers": {},
    "body": "string"
  }
}
```

### Get schedule
`GET /workspaces/:workspaceId/schedules/:scheduleId/`

### Update schedule
`PATCH /workspaces/:workspaceId/schedules/:scheduleId/`

```json
{
  "name": "string",
  "schedule": "string (cron expression)",
  "status": "active | paused",
  "requestTemplate": {
    "method": "string",
    "url": "string",
    "headers": {},
    "body": "string"
  }
}
```

### Delete schedule
`DELETE /workspaces/:workspaceId/schedules/:scheduleId/`

---

## Tokens

### List tokens
`GET /workspaces/:workspaceId/tokens/`

### Create token
`POST /workspaces/:workspaceId/tokens/`

```json
{
  "name": "string (required)"
}
```

The token value is returned once on creation and cannot be retrieved again.

### Delete token
`DELETE /workspaces/:workspaceId/tokens/:tokenId/`

---

## Webhooks

### List webhooks
`GET /workspaces/:workspaceId/webhooks/`

### Create webhook
`POST /workspaces/:workspaceId/webhooks/`

```json
{
  "url": "string (required)",
  "events": ["request.create", "request.complete", "request.fail"]
}
```

### Update webhook
`PATCH /workspaces/:workspaceId/webhooks/:webhookId/`

### Delete webhook
`DELETE /workspaces/:workspaceId/webhooks/:webhookId/`

---

## Workspaces

### Get workspace
`GET /workspaces/:workspaceId/`

### Update workspace
`PATCH /workspaces/:workspaceId/`

### List members
`GET /workspaces/:workspaceId/team`

### Invite member
`POST /workspaces/:workspaceId/team/invite`

```json
{
  "email": "string (required)",
  "role": "admin | member | viewer"
}
```

---

## Request statuses

| Status | Description |
|--------|-------------|
| `pending` | Queued, waiting to be processed |
| `scheduled` | Delayed or scheduled for future execution |
| `processing` | Currently being executed |
| `completed` | Successfully executed (2xx response) |
| `failed` | All attempts exhausted |
| `cancelled` | Manually cancelled |

## Error responses

All errors follow a consistent format:

```json
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Queue not found"
  }
}
```

Common HTTP status codes:

| Code | Meaning |
|------|---------|
| `400` | Invalid request body or parameters |
| `401` | Missing or invalid authentication |
| `403` | Insufficient permissions |
| `404` | Resource not found |
| `409` | Conflict (e.g., duplicate idempotency key) |
| `429` | Rate limit exceeded |
