# Automations

Endpoints under /v1/automations.

Source: https://sourceloop.ai/help/api/automations/

---

| Endpoint | Method | Path | Permission |
| --- | --- | --- | --- |
| List automations | GET | `/v1/automations` | any key |
| Create automation | POST | `/v1/automations` | any key |
| Get automation | GET | `/v1/automations/{id}` | any key |
| Update automation | PATCH | `/v1/automations/{id}` | any key |
| Delete automation | DELETE | `/v1/automations/{id}` | any key |
| Run automation | POST | `/v1/automations/{id}/run` | any key |

Base URL: `https://app.sourceloop.ai/api/v1`

## List automations

`GET /v1/automations`

List alerts

Requires: any valid API key.

The Slack and email alerts on this website (Activation > Alerts in the app), with
the event catalog and the templates a new alert can start from (in `meta`).
Needs automations:read.

### Query parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `website` | string | no | Website domain, e.g. acme.com. Required only when the key covers more than one. |

### Responses

- `200` One row per alert
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X GET "https://app.sourceloop.ai/api/v1/automations?website=acme.com" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY"
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations?website=acme.com",
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
    },
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.get(
    "https://app.sourceloop.ai/api/v1/automations?website=acme.com",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
)
data = res.json()
```

## Create automation

`POST /v1/automations`

Create an alert

Requires: any valid API key.

Create an alert from a spec: `trigger` (event, schedule or threshold), `filters`
(events), `gather` and `condition` (numbers), `compose`, `deliver` and `pacing`.
Start from a template in the list response and edit it. Slack targets need a
channel from a Slack workspace connected in the app. Needs automations:write.

### Responses

- `200` The created alert
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X POST "https://app.sourceloop.ai/api/v1/automations" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "New demo booked",
    "template_id": "new_lead",
    "spec": {
      "version": 1,
      "trigger": {
        "kind": "event",
        "events": [
          "conversion.created"
        ]
      },
      "filters": [
        {
          "field": "conversion",
          "op": "is",
          "values": [
            "Demo booked"
          ]
        }
      ],
      "compose": {
        "template": "new_lead",
        "ai": false
      },
      "deliver": [
        {
          "channel": "email",
          "to": [
            "sales@acme.com"
          ]
        }
      ],
      "pacing": {
        "mode": "each"
      }
    }
  }'
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "name": "New demo booked",
      "template_id": "new_lead",
      "spec": {
        "version": 1,
        "trigger": {
          "kind": "event",
          "events": [
            "conversion.created"
          ]
        },
        "filters": [
          {
            "field": "conversion",
            "op": "is",
            "values": [
              "Demo booked"
            ]
          }
        ],
        "compose": {
          "template": "new_lead",
          "ai": false
        },
        "deliver": [
          {
            "channel": "email",
            "to": [
              "sales@acme.com"
            ]
          }
        ],
        "pacing": {
          "mode": "each"
        }
      }
    }),
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.post(
    "https://app.sourceloop.ai/api/v1/automations",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
    json={
      "name": "New demo booked",
      "template_id": "new_lead",
      "spec": {
        "version": 1,
        "trigger": {
          "kind": "event",
          "events": [
            "conversion.created"
          ]
        },
        "filters": [
          {
            "field": "conversion",
            "op": "is",
            "values": [
              "Demo booked"
            ]
          }
        ],
        "compose": {
          "template": "new_lead",
          "ai": False
        },
        "deliver": [
          {
            "channel": "email",
            "to": [
              "sales@acme.com"
            ]
          }
        ],
        "pacing": {
          "mode": "each"
        }
      }
    },
)
data = res.json()
```

## Get automation

`GET /v1/automations/{id}`

Get an alert and its recent runs

Requires: any valid API key.

### Path parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |

### Responses

- `200` The alert with its last 50 runs and their deliveries
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X GET "https://app.sourceloop.ai/api/v1/automations/{id}" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY"
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations/{id}",
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
    },
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.get(
    "https://app.sourceloop.ai/api/v1/automations/{id}",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
)
data = res.json()
```

## Update automation

`PATCH /v1/automations/{id}`

Update an alert

Requires: any valid API key.

Send `name`, `spec` (the whole spec) or `status` ("active" or "paused").

### Path parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |

### Responses

- `200` The updated alert
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X PATCH "https://app.sourceloop.ai/api/v1/automations/{id}" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY"
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations/{id}",
  {
    method: "PATCH",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
    },
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.patch(
    "https://app.sourceloop.ai/api/v1/automations/{id}",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
)
data = res.json()
```

## Delete automation

`DELETE /v1/automations/{id}`

Delete an alert

Requires: any valid API key.

### Path parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |

### Responses

- `200` Deleted
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X DELETE "https://app.sourceloop.ai/api/v1/automations/{id}" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY"
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations/{id}",
  {
    method: "DELETE",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
    },
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.delete(
    "https://app.sourceloop.ai/api/v1/automations/{id}",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
)
data = res.json()
```

## Run automation

`POST /v1/automations/{id}/run`

Send an alert now

Requires: any valid API key.

Builds the alert from the latest data and queues it to its destinations. `test: true` marks the message as a test.

### Path parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `test` | boolean | no |  |

### Responses

- `200` Where it was queued
- `400` Something was wrong with the request or the credential.
- `429` Too many requests for this workspace in the current minute (`rate-limit-exceeded`), the monthly allowance used (`quota-exceeded`), or too many analytics queries running at once (`too-many-concurrent`). Wait Retry-After seconds and repeat the request unchanged.

### Example (cURL)

```bash
curl -s -X POST "https://app.sourceloop.ai/api/v1/automations/{id}/run" \
  -H "Authorization: Bearer $SOURCELOOP_API_KEY"
```

### Example (Node)

```javascript
const res = await fetch(
  "https://app.sourceloop.ai/api/v1/automations/{id}/run",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SOURCELOOP_API_KEY}`,
    },
  },
);

const data = await res.json();
```

### Example (Python)

```python
import os, requests

res = requests.post(
    "https://app.sourceloop.ai/api/v1/automations/{id}/run",
    headers={"Authorization": f"Bearer {os.environ['SOURCELOOP_API_KEY']}"},
)
data = res.json()
```
