# Task routes: escalate, next, return

URL: /code/api/task/verbs-escalate · Id: `page:code/api/task/verbs-escalate`

> The Task Verbs escalate, next, return as api.sb routes, with inputs, result, refusals and an example.

Reference for [Task](/business/nouns/task), one group of [Task routes](/code/api/task).

### Task.escalate
Escalate moves a Task to the Role its current Role escalates to, with the reason attached. [Verb page](/business/nouns/task/escalate?interface=api).

```text
POST /{namespace}/tasks/{task}/escalate
```

Path: `task`. Body, as JSON: the other inputs. Emits [`Task.escalated`](/business/events/Task.escalated).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `task` | [Task](/business/nouns/task) | Yes | The Task to escalate. |
| `reason` | `text` | Yes | Why the current Role cannot finish it. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `task` | [Task](/business/nouns/task) | Yes | The Task, assigned upward. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| The record is not in a state that allows this Verb, so the call is refused. | [`refused`](/code/api/errors/refused) | Read the record, run the Verb that moves it to an allowed state, then retry. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/tasks/task_tVPKjporKn/escalate \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Example reason"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "task": {
    "$id": "https://api.sb/leaseline.app/tasks/task_tVPKjporKn",
    "$type": "Task",
    "status": "pending",
    "mode": "try"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Task.escalate",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Task.next
Next returns the oldest open Task the calling Worker’s Roles may claim, without claiming it. [Verb page](/business/nouns/task/next?interface=api).

```text
POST /{namespace}/tasks/next
```

Emits [`Task.offered`](/business/events/Task.offered).

**Inputs**

None.

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `task` | [Task](/business/nouns/task) | No | The Task to claim next; empty when the queue is drained. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/tasks/next \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "task": {
    "$id": "https://api.sb/leaseline.app/tasks/task_tVPKjporKn",
    "$type": "Task",
    "status": "pending",
    "mode": "try"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Task.next",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Task.return
Return hands an offered Task back to its sender, unchanged, with the reason the receiver cannot take it. [Verb page](/business/nouns/task/return?interface=api).

```text
POST /{namespace}/tasks/{task}/return
```

Path: `task`. Body, as JSON: the other inputs. Emits [`Task.returned`](/business/events/Task.returned).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `task` | [Task](/business/nouns/task) | Yes | The Task to hand back. |
| `reason` | `text` | Yes | What is missing, or why the Task is outside the receiver’s lane. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `task` | [Task](/business/nouns/task) | Yes | The Task, back with its sender. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/tasks/task_tVPKjporKn/return \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Example reason"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "task": {
    "$id": "https://api.sb/leaseline.app/tasks/task_tVPKjporKn",
    "$type": "Task",
    "status": "pending",
    "mode": "try"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Task.return",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```