# Update daemon job run

> Source: https://truto.one/docs/api-reference/admin/daemon-job-runs/update/

`PATCH /daemon-job-run/{id}`

Resource: **Daemon job runs**

Your daemon process uses this to report a run's progress.

A run does not move back. A `completed`, `failed` or `stopped` run cannot be set to `created` or `running`, and a `running` run cannot be set to `created` (a daemon runs any `created` run it is given). Such a request is a `400` and changes nothing: its `truto_error_code` is `daemon_job_run_status_transition`, with the stored status in `from` and the one sent in `to`. A finished run may be set to another finished status. To run the daemon job again, create a new run.

`started_at` and `finished_at` must be ISO 8601 dates and times (or `null`). A body that isn't a JSON object, or a date that can't be read, is a `400` and changes nothing: `fields` names the dates.

## Path parameters

- **`id`** _(string, required)_

## Request body

- **`status`** _(string)_
  Allowed: `created`, `running`, `completed`, `failed`, `stopped`
- **`started_at`** _(string)_
- **`finished_at`** _(string)_

## Response body

- **`id`** _(string)_
  The ID of the daemon job run.
- **`daemon_job_id`** _(string)_
  The daemon job this run belongs to.
- **`daemon_id`** _(string)_
  The daemon that runs it.
- **`environment_id`** _(string)_
- **`status`** _(string)_
  The run's status. A new run is `created`; your daemon process updates it.
  Allowed: `created`, `running`, `completed`, `failed`, `stopped`
- **`args`** _(object)_
  The arguments for the run, checked against the daemon job's `args_schema` and `args_validation`.
- **`daemon_group_key`** _(string)_
- **`started_at`** _(string)_
- **`finished_at`** _(string)_
- **`created_at`** _(string)_
- **`updated_at`** _(string)_

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | The body is not a JSON object, `started_at` or `finished_at` is not an ISO 8601 date and time (named in `fields`), or `status` is unknown or one the run cannot move to (`truto_error_code` `daemon_job_run_status_transition`, with `from` and `to`). Nothing is changed. |
| `404` | Daemon job run not found |

## Code examples

### curl

```bash
curl -X PATCH 'https://api.truto.one/daemon-job-run/{id}' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "status": "created",
  "started_at": "your_started_at",
  "finished_at": "your_finished_at"
}'
```

### JavaScript

```javascript
const body = {
  "status": "created",
  "started_at": "your_started_at",
  "finished_at": "your_finished_at"
};

const response = await fetch('https://api.truto.one/daemon-job-run/{id}', {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/daemon-job-run/{id}"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "status": "created",
    "started_at": "your_started_at",
    "finished_at": "your_finished_at"
}

response = requests.patch(url, headers=headers, params=params, json=payload)
print(response.json())
```
