---
title: "Create a trigger"
---

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

# Create a trigger

Path: CloudRaker Workspace API › Workspace Triggers

`POST /triggers`

## Authentication

- `bearerAuth`, http, header `Authorization`

## Request body

_Required._

- `name` (`createTrigger.name`; string, required)
  - minLength 1; maxLength 80
- `when` (`createTrigger.when`; one of, required)
  - one of:
    - `object`
      - `kind` (`createTrigger.when.1.kind`; string, required)
      - `schedule` (`createTrigger.when.1.schedule`; one of, required)
        - one of:
          - `object`
            - `kind` (`createTrigger.when.1.schedule.1.kind`; string, required)
            - `expression` (`createTrigger.when.1.schedule.1.expression`; string, required)
              - minLength 1; maxLength 200
            - `timezone` (`createTrigger.when.1.schedule.1.timezone`; string, required)
              - minLength 1; maxLength 100
          - `object`
            - `kind` (`createTrigger.when.1.schedule.2.kind`; string, required)
            - `at` (`createTrigger.when.1.schedule.2.at`; string, required)
              - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
    - `object`
      - `kind` (`createTrigger.when.2.kind`; string, required)
      - `address` (`createTrigger.when.2.address`; string, required)
        - format `email`; maxLength 254; pattern `^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$`
      - `from` (`createTrigger.when.2.from`; array<string>, optional)
        - format `email`; pattern `^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$`
    - `object`
      - `kind` (`createTrigger.when.3.kind`; string, required)
      - `slug` (`createTrigger.when.3.slug`; string, required)
        - pattern `^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$`
    - `object`
      - `kind` (`createTrigger.when.4.kind`; string, required)
- `open` (`createTrigger.open`; object, required)
  - `agentIds` (`createTrigger.open.agentIds`; array<string>, required)
    - minLength 1; maxLength 128
  - `spaces` (`createTrigger.open.spaces`; array<object>, required)
    - `spaceId` (`createTrigger.open.spaces.spaceId`; string, required)
      - minLength 1; maxLength 128
    - `access` (`createTrigger.open.spaces.access`; string, required)
      - one of `"read"`, `"commit"`
  - `instruction` (`createTrigger.open.instruction`; string, required)
    - minLength 1; maxLength 4000
  - `threadPolicy` (`createTrigger.open.threadPolicy`; string, required)
    - one of `"new"`, `"reuse"`
  - `filesFrom` (`createTrigger.open.filesFrom`; string, required)
    - one of `"payload"`, `"none"`
  - `title` (`createTrigger.open.title`; string, optional)
    - maxLength 200
- `permissions` (`createTrigger.permissions`; object, required)
  - `runAsUserId` (`createTrigger.permissions.runAsUserId`; string, required)
    - minLength 1; maxLength 128
- `enabled` (`createTrigger.enabled`; boolean, optional)
  - default `true`

## Example request

```json
{
  "name": "string",
  "enabled": true,
  "when": {
    "kind": "schedule",
    "schedule": {
      "kind": "cron",
      "expression": "string",
      "timezone": "string"
    }
  },
  "open": {
    "agentIds": [
      "string"
    ],
    "spaces": [
      {
        "spaceId": "string",
        "access": "read"
      }
    ],
    "instruction": "string",
    "threadPolicy": "new",
    "title": "string",
    "filesFrom": "payload"
  },
  "permissions": {
    "runAsUserId": "string"
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://api.cloudraker.com/triggers \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "string",
  "enabled": true,
  "when": {
    "kind": "schedule",
    "schedule": {
      "kind": "cron",
      "expression": "string",
      "timezone": "string"
    }
  },
  "open": {
    "agentIds": [
      "string"
    ],
    "spaces": [
      {
        "spaceId": "string",
        "access": "read"
      }
    ],
    "instruction": "string",
    "threadPolicy": "new",
    "title": "string",
    "filesFrom": "payload"
  },
  "permissions": {
    "runAsUserId": "string"
  }
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/triggers';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    name: 'string',
    enabled: true,
    when: {
      kind: 'schedule',
      schedule: {kind: 'cron', expression: 'string', timezone: 'string'}
    },
    open: {
      agentIds: ['string'],
      spaces: [{spaceId: 'string', access: 'read'}],
      instruction: 'string',
      threadPolicy: 'new',
      title: 'string',
      filesFrom: 'payload'
    },
    permissions: {runAsUserId: 'string'}
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/triggers"

payload = {
    "name": "string",
    "enabled": True,
    "when": {
        "kind": "schedule",
        "schedule": {
            "kind": "cron",
            "expression": "string",
            "timezone": "string"
        }
    },
    "open": {
        "agentIds": ["string"],
        "spaces": [
            {
                "spaceId": "string",
                "access": "read"
            }
        ],
        "instruction": "string",
        "threadPolicy": "new",
        "title": "string",
        "filesFrom": "payload"
    },
    "permissions": { "runAsUserId": "string" }
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 201

The trigger and its one-time secret.

#### Example

```json
{
  "data": {
    "name": "string",
    "enabled": true,
    "when": {
      "kind": "schedule",
      "schedule": {
        "kind": "cron",
        "expression": "string",
        "timezone": "string"
      }
    },
    "open": {
      "agentIds": [
        "string"
      ],
      "spaces": [
        {
          "spaceId": "string",
          "access": "read"
        }
      ],
      "instruction": "string",
      "threadPolicy": "new",
      "title": "string",
      "filesFrom": "payload"
    },
    "permissions": {
      "runAsUserId": "string"
    },
    "id": "string",
    "lastRun": {
      "status": "opened",
      "sessionId": "string",
      "message": "string",
      "at": "2019-08-24T14:15:22Z"
    },
    "nextRunAt": "2019-08-24T14:15:22Z",
    "triggerRef": "string",
    "createdAt": "2019-08-24T14:15:22Z",
    "updatedAt": "2019-08-24T14:15:22Z",
    "legacy": {
      "channelId": "string",
      "channelType": "email",
      "automationId": "string"
    }
  },
  "secret": "string"
}
```

- `data` (`createTrigger.response.201.data`; object, required)
  - `name` (`createTrigger.response.201.data.name`; string, required)
    - minLength 1; maxLength 80
  - `when` (`createTrigger.response.201.data.when`; any of, required)
    - any of:
      - `Option 1`
        - one of:
          - `object`
            - `kind` (`createTrigger.response.201.data.when.1.1.kind`; string, required)
            - `schedule` (`createTrigger.response.201.data.when.1.1.schedule`; one of, required)
              - one of:
                - `object`
                  - `kind` (`createTrigger.response.201.data.when.1.1.schedule.1.kind`; string, required)
                  - `expression` (`createTrigger.response.201.data.when.1.1.schedule.1.expression`; string, required)
                    - minLength 1; maxLength 200
                  - `timezone` (`createTrigger.response.201.data.when.1.1.schedule.1.timezone`; string, required)
                    - minLength 1; maxLength 100
                - `object`
                  - `kind` (`createTrigger.response.201.data.when.1.1.schedule.2.kind`; string, required)
                  - `at` (`createTrigger.response.201.data.when.1.1.schedule.2.at`; string, required)
                    - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
          - `object`
            - `kind` (`createTrigger.response.201.data.when.1.2.kind`; string, required)
            - `address` (`createTrigger.response.201.data.when.1.2.address`; string, required)
              - format `email`; maxLength 254; pattern `^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$`
            - `from` (`createTrigger.response.201.data.when.1.2.from`; array<string>, optional)
              - format `email`; pattern `^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$`
          - `object`
            - `kind` (`createTrigger.response.201.data.when.1.3.kind`; string, required)
            - `slug` (`createTrigger.response.201.data.when.1.3.slug`; string, required)
              - pattern `^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$`
          - `object`
            - `kind` (`createTrigger.response.201.data.when.1.4.kind`; string, required)
      - `object`
        - `kind` (`createTrigger.response.201.data.when.2.kind`; string, required)
        - `slug` (`createTrigger.response.201.data.when.2.slug`; string, required)
        - `secretPreview` (`createTrigger.response.201.data.when.2.secretPreview`; string, required)
  - `open` (`createTrigger.response.201.data.open`; object, required)
    - `agentIds` (`createTrigger.response.201.data.open.agentIds`; array<string>, required)
      - minLength 1; maxLength 128
    - `spaces` (`createTrigger.response.201.data.open.spaces`; array<object>, required)
      - `spaceId` (`createTrigger.response.201.data.open.spaces.spaceId`; string, required)
        - minLength 1; maxLength 128
      - `access` (`createTrigger.response.201.data.open.spaces.access`; string, required)
        - one of `"read"`, `"commit"`
    - `instruction` (`createTrigger.response.201.data.open.instruction`; string, required)
      - minLength 1; maxLength 4000
    - `threadPolicy` (`createTrigger.response.201.data.open.threadPolicy`; string, required)
      - one of `"new"`, `"reuse"`
    - `filesFrom` (`createTrigger.response.201.data.open.filesFrom`; string, required)
      - one of `"payload"`, `"none"`
    - `title` (`createTrigger.response.201.data.open.title`; string, optional)
      - maxLength 200
  - `permissions` (`createTrigger.response.201.data.permissions`; object, required)
    - `runAsUserId` (`createTrigger.response.201.data.permissions.runAsUserId`; string, required)
      - minLength 1; maxLength 128
  - `id` (`createTrigger.response.201.data.id`; string, required)
    - maxLength 128; pattern `^trg_[A-Za-z0-9_-]+$`
  - `nextRunAt` (`createTrigger.response.201.data.nextRunAt`; any of, required)
    - any of: `string`, `null`
  - `triggerRef` (`createTrigger.response.201.data.triggerRef`; string, required)
  - `createdAt` (`createTrigger.response.201.data.createdAt`; string, required)
    - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
  - `updatedAt` (`createTrigger.response.201.data.updatedAt`; string, required)
    - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
  - `enabled` (`createTrigger.response.201.data.enabled`; boolean, optional)
    - default `true`
  - `lastRun` (`createTrigger.response.201.data.lastRun`; object, optional)
    - `status` (`createTrigger.response.201.data.lastRun.status`; string, required)
      - one of `"opened"`, `"busy"`, `"needs_input"`, `"blocked"`, `"error"`
    - `at` (`createTrigger.response.201.data.lastRun.at`; string, required)
      - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
    - `sessionId` (`createTrigger.response.201.data.lastRun.sessionId`; string, optional)
      - minLength 1; maxLength 128
    - `message` (`createTrigger.response.201.data.lastRun.message`; string, optional)
      - maxLength 1000
  - `legacy` (`createTrigger.response.201.data.legacy`; object, optional)
    - `channelId` (`createTrigger.response.201.data.legacy.channelId`; string, optional)
    - `channelType` (`createTrigger.response.201.data.legacy.channelType`; string, optional)
      - one of `"email"`, `"webhook"`
    - `automationId` (`createTrigger.response.201.data.legacy.automationId`; string, optional)
- `secret` (`createTrigger.response.201.secret`; string, required)

### 400

`invalid_trigger` — the email address does not belong to this organization and environment; `invalid_schedule` — the schedule is not valid.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createTrigger.response.400.error`; string, required) — The sentence a human reads.
- `error_code` (`createTrigger.response.400.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createTrigger.response.400.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createTrigger.response.400.issues.path`; string, required)
  - `code` (`createTrigger.response.400.issues.code`; string, required)
  - `message` (`createTrigger.response.400.issues.message`; string, required)

### 403

`run_as_inactive` — the executing member is not active in this organization.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createTrigger.response.403.error`; string, required) — The sentence a human reads.
- `error_code` (`createTrigger.response.403.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createTrigger.response.403.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createTrigger.response.403.issues.path`; string, required)
  - `code` (`createTrigger.response.403.issues.code`; string, required)
  - `message` (`createTrigger.response.403.issues.message`; string, required)

### 404

`space_not_found` — a named space does not exist or the executing member may not contribute to it; `agent_not_found` — a named agent does not exist.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createTrigger.response.404.error`; string, required) — The sentence a human reads.
- `error_code` (`createTrigger.response.404.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createTrigger.response.404.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createTrigger.response.404.issues.path`; string, required)
  - `code` (`createTrigger.response.404.issues.code`; string, required)
  - `message` (`createTrigger.response.404.issues.message`; string, required)

### 409

`trigger_conflict` — that webhook address or email address is already used in this organization, or a channel key rotation is unsettled; `trigger_limit` — 50 enabled triggers is the maximum; `trigger_migration_in_progress` — a legacy transfer still owns this source.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createTrigger.response.409.error`; string, required) — The sentence a human reads.
- `error_code` (`createTrigger.response.409.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createTrigger.response.409.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createTrigger.response.409.issues.path`; string, required)
  - `code` (`createTrigger.response.409.issues.code`; string, required)
  - `message` (`createTrigger.response.409.issues.message`; string, required)

### 422

`agent_not_published` — a named agent has no published version.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createTrigger.response.422.error`; string, required) — The sentence a human reads.
- `error_code` (`createTrigger.response.422.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createTrigger.response.422.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createTrigger.response.422.issues.path`; string, required)
  - `code` (`createTrigger.response.422.issues.code`; string, required)
  - `message` (`createTrigger.response.422.issues.message`; string, required)


Source: https://docs.cloudraker.com/workspace/api/workspace-triggers/create-trigger/index.md
