# Metric routes: update, delete

URL: /code/api/metric/records-update · Id: `page:code/api/metric/records-update`

> The Metric Verbs update, delete as api.sb routes, with inputs, result, refusals and an example.

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

### Metric.update
Changes the given properties of a Metric. [Verb page](/business/nouns/metric/update?interface=api).

```text
PATCH /{namespace}/metrics/{id}
```

Path: `id`. Body, as JSON: the other inputs. Emits `Metric.updated`.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | The id of the Metric. |
| `query` | `text` | No | How it is computed. An agent never varies the Metrics it is judged by. Never randomized. |
| `unit` | `string` | No | The unit, such as dollars or percent. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `metric` | [Metric](/business/nouns/metric) | Yes | The Metric. |

**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 PATCH https://api.sb/leaseline.app/metrics/metric_GXFHAlK100 \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"Example query"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "metric": {
    "$id": "https://api.sb/leaseline.app/metrics/metric_GXFHAlK100",
    "$type": "Metric",
    "query": "Example query",
    "status": "draft"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Metric.update",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Metric.delete
Deletes a Metric: a soft delete that keeps its history, undone by `Thing.restore`. [Verb page](/business/nouns/metric/delete?interface=api).

```text
DELETE /{namespace}/metrics/{id}
```

Path: `id`. Emits `Metric.deleted`.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | The id of the Metric. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `metric` | [Metric](/business/nouns/metric) | Yes | The Metric. |

**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 DELETE https://api.sb/leaseline.app/metrics/metric_GXFHAlK100 \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "metric": {
    "$id": "https://api.sb/leaseline.app/metrics/metric_GXFHAlK100",
    "$type": "Metric",
    "query": "Example query",
    "status": "draft"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Metric.delete",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```