> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parsalink.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Automation Rules API

> REST endpoints for managing automation rules programmatically — list, inspect, create, update, activate, and delete rules.

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "linear-gradient(90deg, #143D4E 0%, #1C758A 100%)",
color: "#FFFFFF",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
boxShadow: "0 8px 24px rgba(20, 61, 78, 0.18)"
}}
>
  Automation
</div>

## Endpoints

<div
  style={{
background: "linear-gradient(135deg, rgba(20, 61, 78, 0.04) 0%, rgba(28, 117, 138, 0.08) 100%)",
border: "1px solid #CDD1D3",
borderRadius: "18px",
padding: "8px 12px 2px 12px",
marginBottom: "22px",
boxShadow: "0 10px 30px rgba(20, 61, 78, 0.06)"
}}
>
  | Method   | Path                                      | Description                    |
  | -------- | ----------------------------------------- | ------------------------------ |
  | `GET`    | `/api/automations/rules/`                 | List automation rules          |
  | `POST`   | `/api/automations/rules/`                 | Create a rule                  |
  | `GET`    | `/api/automations/rules/{id}/`            | Get a rule                     |
  | `PATCH`  | `/api/automations/rules/{id}/`            | Update a rule                  |
  | `DELETE` | `/api/automations/rules/{id}/`            | Delete a rule                  |
  | `POST`   | `/api/automations/rules/{id}/activate/`   | Activate a rule                |
  | `POST`   | `/api/automations/rules/{id}/deactivate/` | Deactivate a rule              |
  | `GET`    | `/api/automations/rules/{id}/logs/`       | List execution logs for a rule |
</div>

***

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "rgba(48, 200, 202, 0.12)",
color: "#1C758A",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
border: "1px solid rgba(48, 200, 202, 0.28)"
}}
>
  Rules
</div>

## List Rules

```http theme={null}
GET /api/automations/rules/
Authorization: Bearer <token>
```

**Response:**

```json theme={null}
{
  "count": 7,
  "results": [
    {
      "id": "rul_01HX...",
      "name": "New Lead Follow-Up",
      "trigger": "lead_created",
      "isActive": true,
      "stepCount": 4,
      "enrolledCount": 142,
      "createdAt": "2025-01-10T09:00:00Z",
      "updatedAt": "2025-03-01T11:00:00Z"
    }
  ]
}
```

***

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "rgba(255, 111, 97, 0.12)",
color: "#FF6F61",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
border: "1px solid rgba(255, 111, 97, 0.24)"
}}
>
  Rule Details
</div>

## Get a Rule

```http theme={null}
GET /api/automations/rules/{id}/
Authorization: Bearer <token>
```

<div style={{ border: "1px solid rgba(48, 200, 202, 0.22)", borderRadius: "16px", padding: "16px 18px", marginBottom: "20px", color: "#2C768D", boxShadow: "0 10px 26px rgba(28, 117, 138, 0.08)" }} className="bg-white dark:bg-black dark:border-white/10 dark:text-white [&_*]:dark:text-white dark:shadow-none">
  Returns the full rule definition including trigger, conditions, and all steps.
</div>

**Response:**

```json theme={null}
{
  "id": "rul_01HX...",
  "name": "New Lead Follow-Up",
  "trigger": "lead_created",
  "triggerConditions": [
    {
      "field": "source",
      "operator": "eq",
      "value": "website_form"
    }
  ],
  "exitConditions": [
    {
      "field": "status",
      "operator": "eq",
      "value": "converted"
    }
  ],
  "steps": [
    {
      "type": "send_email",
      "order": 1,
      "config": {
        "mode": "template",
        "templateId": "tmpl_01HX..."
      }
    },
    {
      "type": "wait",
      "order": 2,
      "config": {
        "duration": 3,
        "unit": "days"
      }
    },
    {
      "type": "create_task",
      "order": 3,
      "config": {
        "name": "Follow up with {{lead.firstName}}",
        "assignTo": "assigned_user",
        "dueDays": 1
      }
    }
  ],
  "isActive": true,
  "enrolledCount": 142,
  "createdAt": "2025-01-10T09:00:00Z"
}
```

***

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "linear-gradient(90deg, #143D4E 0%, #1C758A 100%)",
color: "#FFFFFF",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
boxShadow: "0 8px 24px rgba(20, 61, 78, 0.18)"
}}
>
  Creation
</div>

## Create a Rule

```http theme={null}
POST /api/automations/rules/
Authorization: Bearer <token>
Content-Type: application/json
```

**Request body:**

```json theme={null}
{
  "name": "Qualified Lead Fast-Track",
  "trigger": "lead_status_changed",
  "triggerConditions": [
    { "field": "status", "operator": "eq", "value": "qualified" }
  ],
  "exitConditions": [],
  "steps": [
    {
      "type": "assign_user",
      "order": 1,
      "config": {
        "mode": "round_robin",
        "userIds": ["usr_01HX...", "usr_02HX...", "usr_03HX..."]
      }
    },
    {
      "type": "send_notification",
      "order": 2,
      "config": {
        "recipients": ["assigned_user"],
        "message": "New qualified lead assigned: {{lead.firstName}} {{lead.lastName}}"
      }
    }
  ]
}
```

<div style={{ border: "1px solid rgba(48, 200, 202, 0.22)", borderRadius: "16px", padding: "16px 18px", marginBottom: "20px", color: "#2C768D", boxShadow: "0 10px 26px rgba(28, 117, 138, 0.08)" }} className="bg-white dark:bg-black dark:border-white/10 dark:text-white [&_*]:dark:text-white dark:shadow-none">
  The rule is created in **inactive** state. Call the activate endpoint to start it.
</div>

**Response:** `201 Created` with the full rule object.

***

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "rgba(48, 200, 202, 0.12)",
color: "#1C758A",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
border: "1px solid rgba(48, 200, 202, 0.28)"
}}
>
  Activation
</div>

## Activate / Deactivate a Rule

```http theme={null}
POST /api/automations/rules/{id}/activate/
Authorization: Bearer <token>
```

```http theme={null}
POST /api/automations/rules/{id}/deactivate/
Authorization: Bearer <token>
```

<div style={{ border: "1px solid rgba(48, 200, 202, 0.22)", borderRadius: "16px", padding: "16px 18px", marginBottom: "20px", color: "#2C768D", boxShadow: "0 10px 26px rgba(28, 117, 138, 0.08)" }} className="bg-white dark:bg-black dark:border-white/10 dark:text-white [&_*]:dark:text-white dark:shadow-none">
  Both return `200 OK` with the updated rule object.
</div>

***

<div
  style={{ 
display: "inline-flex",
alignItems: "center",
gap: "8px",
background: "rgba(255, 111, 97, 0.12)",
color: "#FF6F61",
fontSize: "12px",
fontWeight: "700",
marginBottom: "10px",
padding: "8px 14px",
letterSpacing: "0.08em",
textTransform: "uppercase",
borderRadius: "999px",
border: "1px solid rgba(255, 111, 97, 0.24)"
}}
>
  Logs
</div>

## Get Execution Logs

```http theme={null}
GET /api/automations/rules/{id}/logs/
Authorization: Bearer <token>
```

**Query Parameters:**

<div
  style={{

border: "1px solid #CDD1D3",
borderRadius: "18px",
padding: "8px 12px 2px 12px",
marginBottom: "22px",
boxShadow: "0 10px 30px rgba(20, 61, 78, 0.05)"
}}
  className="dark:!bg-black dark:!border-gray-800 dark:shadow-none"
>
  | Parameter | Type    | Description                                       |
  | --------- | ------- | ------------------------------------------------- |
  | `page`    | integer | Page number                                       |
  | `status`  | string  | `completed`, `failed`, `cancelled`, `in_progress` |
  | `after`   | ISO8601 | Logs after this date                              |
</div>

**Response:**

```json theme={null}
{
  "count": 58,
  "results": [
    {
      "id": "log_01HX...",
      "enrolledRecordType": "lead",
      "enrolledRecordId": "ld_01HX...",
      "status": "completed",
      "completedSteps": 3,
      "totalSteps": 3,
      "startedAt": "2025-03-20T08:00:00Z",
      "completedAt": "2025-03-23T08:01:00Z"
    }
  ]
}
```
