# Automations API

Every automations call: what to send, what comes back, and copy-ready examples.

## List automations

`GET /automations` (scope: automations:read)

```bash
curl "https://api.usetotems.com/v1/automations" \
  -H "Authorization: Bearer $TOTEMS_KEY"
```

```json
{
  "data": [],
  "request_id": "req_..."
}
```

## Make an automation

`POST /automations` (scope: automations:write)

```bash
curl -X POST "https://api.usetotems.com/v1/automations" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Big sales",
    "trigger": "sale.created",
    "action": "webhook",
    "url": "https://example.com/hooks/totems",
    "filters": [
      {
        "field": "amount_cents",
        "op": "at_least",
        "value": "100000"
      }
    ]
  }'
```

```json
{
  "data": {
    "id": "2aa2d9d5-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "name": "Big sales",
    "trigger": "sale.created",
    "filters": [
      {
        "op": "at_least",
        "field": "amount_cents",
        "value": "100000"
      }
    ],
    "action": "webhook",
    "config": {
      "url": "https://example.com/hooks/totems"
    },
    "enabled": false,
    "fails_in_row": 0,
    "created_at": "2026-12-03T23:43:26.290Z",
    "signing_secret": "whsec_..."
  },
  "request_id": "req_..."
}
```

## One automation

`GET /automations/{id}` (scope: automations:read)

```bash
curl "https://api.usetotems.com/v1/automations/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a" \
  -H "Authorization: Bearer $TOTEMS_KEY"
```

```json
{
  "data": {
    "id": "2aa2d9d5-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "name": "Big sales",
    "trigger": "sale.created",
    "filters": [
      {
        "op": "at_least",
        "field": "amount_cents",
        "value": "100000"
      }
    ],
    "action": "webhook",
    "config": {
      "url": "https://example.com/hooks/totems"
    },
    "enabled": false,
    "fails_in_row": 0,
    "created_at": "2026-12-03T23:43:26.290Z"
  },
  "request_id": "req_..."
}
```

## Edit an automation

`PATCH /automations/{id}` (scope: automations:write)

```bash
curl -X PATCH "https://api.usetotems.com/v1/automations/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Sales over $1,000"
  }'
```

```json
{
  "data": {
    "id": "2aa2d9d5-7c15-4e2b-8d44-5b6a7c8d9e0f",
    "name": "Sales over $1,000",
    "trigger": "sale.created",
    "filters": [
      {
        "op": "at_least",
        "field": "amount_cents",
        "value": "100000"
      }
    ],
    "action": "webhook",
    "config": {
      "url": "https://example.com/hooks/totems"
    },
    "enabled": false,
    "fails_in_row": 0,
    "created_at": "2026-12-03T23:43:26.290Z"
  },
  "request_id": "req_..."
}
```

## Delete an automation

`DELETE /automations/{id}` (scope: automations:write)

```bash
curl -X DELETE "https://api.usetotems.com/v1/automations/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

```json
{
  "data": {
    "deleted": true
  },
  "request_id": "req_..."
}
```

## Send a test

`POST /automations/{id}/test` (scope: automations:write)

```bash
curl -X POST "https://api.usetotems.com/v1/automations/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/test" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{}'
```

## Last 100 runs

`GET /automations/{id}/runs` (scope: automations:read)

```bash
curl "https://api.usetotems.com/v1/automations/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/runs" \
  -H "Authorization: Bearer $TOTEMS_KEY"
```

```json
{
  "data": [],
  "request_id": "req_..."
}
```

## Try a failed run again

`POST /automations/runs/{id}/retry` (scope: automations:write)

```bash
curl -X POST "https://api.usetotems.com/v1/automations/runs/6f1d2c9a-3b47-4c0e-9a55-1f2e3d4c5b6a/retry" \
  -H "Authorization: Bearer $TOTEMS_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{}'
```
