# Start a job run

> Source: https://docs.clonepartner.com/api-reference/jobs/run-job/

`POST /api/jobs/{id}/run`

Creates a new job run and begins DAG execution using the job's snapshotted
template YAML and pinned task versions (captured at job creation time).
Optionally specify a subset of tasks to run.

**Operation ID:** `runJob`

## Authentication

### Option 1

- **BearerAuth** (`http bearer`)
  API key token. Create via POST /api/api-keys. Format: `envoy_<hex>`

### Option 2

- **CookieAuth** (`apiKey`)
  Session cookie set after login + TOTP verification

## Path parameters

- `id` — `integer`, `required`
  Resource ID

## Request body

### `application/json`

- Type: `object`
- Properties:
  - `tasks` (`array<string>`) — Subset of task keys to run (omit to run all)
    - Description: Subset of task keys to run (omit to run all)
    - Items:
      - Type: `string`
  - `skip_deps` (`boolean`) — When true and `tasks` is a non-empty array, run only the selected task keys without expanding their upstream depends_on tasks. Ignored when `tasks` is omitted or empty. Stored on the job run so resume behaves identically.

## Success responses

### 201

Job run created and started

**Content type:** `application/json`

- Reference: `JobRun`
  - Type: `object`
  - Properties:
    - `id` (`integer`)
    - `job_id` (`integer`)
    - `status` (`string`)
      - Allowed values: `pending`, `running`, `paused`, `completed`, `failed`, `cancelled`
    - `started_at` (`string | null`)
      - Format: `date-time`
      - Nullable: yes
    - `completed_at` (`string | null`)
      - Format: `date-time`
      - Nullable: yes
    - `duration_ms` (`integer | null`)
      - Nullable: yes
    - `error_message` (`string | null`)
      - Nullable: yes
    - `selected_tasks` (`string | null`) — JSON-encoded array of task keys to run (null = all)
      - Description: JSON-encoded array of task keys to run (null = all)
      - Nullable: yes
    - `run_state` (`string | null`) — Internal DAG execution state (JSON)
      - Description: Internal DAG execution state (JSON)
      - Nullable: yes
    - `skip_deps` (`integer | null`) — 1 when selected tasks should run without their upstream depends_on tasks; 0/null otherwise.
      - Description: 1 when selected tasks should run without their upstream depends_on tasks; 0/null otherwise.
      - Nullable: yes
    - `created_at` (`string`)
      - Format: `date-time`
    - `updated_at` (`string`)
      - Format: `date-time`

## Error responses

### 404

Resource not found

**Content type:** `application/json`

- Reference: `Error`
  - Type: `object`
  - Properties:
    - `error` (`string`)
      - Example: `NOT_FOUND`
    - `message` (`string`)
      - Example: `Resource not found`

Example:

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

## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/jobs/YOUR_ID/run' \
  --header 'Authorization: Bearer $API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "tasks": [
    "string"
  ],
  "skip_deps": true
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/jobs/YOUR_ID/run', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "tasks": [
      "string"
    ],
    "skip_deps": true
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
