> This page is for Workspace app.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.cloudraker.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.cloudraker.com/_mcp/server.

# Create a trigger

POST https://api.cloudraker.com/triggers
Content-Type: application/json

Reference: https://docs.cloudraker.com/workspace/api/workspace-triggers/create-trigger

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects an object.

- `name` (string, required)
- `when` (TriggersPostRequestBodyContentApplicationJsonSchemaWhen, required)
- `open` (TriggersPostRequestBodyContentApplicationJsonSchemaOpen, required)
- `permissions` (TriggersPostRequestBodyContentApplicationJsonSchemaPermissions, required)
- `enabled` (boolean, optional, default: true)

## Response

### 201

The trigger and its one-time secret.

- `data` (TriggersPostResponsesContentApplicationJsonSchemaData, required)
- `secret` (string, required)

## Errors

### 400 Bad Request Error

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

- `error` (string, required) — The sentence a human reads.
- `error_code` (string, required) — The stable snake_case branch key.
- `issues` (list of ErrorEnvelopeIssuesItems, optional) — Per-field detail, present only on a validation failure.

### 403 Forbidden Error

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

- `error` (string, required) — The sentence a human reads.
- `error_code` (string, required) — The stable snake_case branch key.
- `issues` (list of ErrorEnvelopeIssuesItems, optional) — Per-field detail, present only on a validation failure.

### 404 Not Found Error

`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.

- `error` (string, required) — The sentence a human reads.
- `error_code` (string, required) — The stable snake_case branch key.
- `issues` (list of ErrorEnvelopeIssuesItems, optional) — Per-field detail, present only on a validation failure.

### 409 Conflict Error

`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.

- `error` (string, required) — The sentence a human reads.
- `error_code` (string, required) — The stable snake_case branch key.
- `issues` (list of ErrorEnvelopeIssuesItems, optional) — Per-field detail, present only on a validation failure.

### 422 Unprocessable Entity Error

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

- `error` (string, required) — The sentence a human reads.
- `error_code` (string, required) — The stable snake_case branch key.
- `issues` (list of ErrorEnvelopeIssuesItems, optional) — Per-field detail, present only on a validation failure.

## Types

### TriggersPostRequestBodyContentApplicationJsonSchemaWhen

- TriggersPostRequestBodyContentApplicationJsonSchemaWhen0
- TriggersPostRequestBodyContentApplicationJsonSchemaWhen1
- TriggersPostRequestBodyContentApplicationJsonSchemaWhen2
- TriggersPostRequestBodyContentApplicationJsonSchemaWhen3

### TriggersPostRequestBodyContentApplicationJsonSchemaOpen

- `agentIds` (list of string, required)
- `spaces` (list of TriggersPostRequestBodyContentApplicationJsonSchemaOpenSpacesItems, required)
- `instruction` (string, required)
- `threadPolicy` (enum, required)
  - Allowed values: `new`, `reuse`
- `filesFrom` (enum, required)
  - Allowed values: `payload`, `none`
- `title` (string, optional)

### TriggersPostRequestBodyContentApplicationJsonSchemaPermissions

- `runAsUserId` (string, required)

### TriggersPostResponsesContentApplicationJsonSchemaData

- `name` (string, required)
- `when` (TriggersPostResponsesContentApplicationJsonSchemaDataWhen, required)
- `open` (TriggersPostResponsesContentApplicationJsonSchemaDataOpen, required)
- `permissions` (TriggersPostResponsesContentApplicationJsonSchemaDataPermissions, required)
- `id` (string, required)
- `nextRunAt` (datetime, required, nullable)
- `triggerRef` (string, required)
- `createdAt` (datetime, required)
- `updatedAt` (datetime, required)
- `enabled` (boolean, optional, default: true)
- `lastRun` (TriggersPostResponsesContentApplicationJsonSchemaDataLastRun, optional)
- `legacy` (TriggersPostResponsesContentApplicationJsonSchemaDataLegacy, optional)

### ErrorEnvelopeIssuesItems

- `path` (string, required)
- `code` (string, required)
- `message` (string, required)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhen0

- `kind` ("schedule", required)
- `schedule` (TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule, required)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhen1

- `kind` ("email", required)
- `address` (string, required)
- `from` (list of string, optional)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhen2

- `kind` ("webhook", required)
- `slug` (string, required)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhen3

- `kind` ("manual", required)

### TriggersPostRequestBodyContentApplicationJsonSchemaOpenSpacesItems

- `spaceId` (string, required)
- `access` (enum, required)
  - Allowed values: `read`, `commit`

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen

- TriggersPostResponsesContentApplicationJsonSchemaDataWhen0
- TriggersPostResponsesContentApplicationJsonSchemaDataWhen1

### TriggersPostResponsesContentApplicationJsonSchemaDataOpen

- `agentIds` (list of string, required)
- `spaces` (list of TriggersPostResponsesContentApplicationJsonSchemaDataOpenSpacesItems, required)
- `instruction` (string, required)
- `threadPolicy` (enum, required)
  - Allowed values: `new`, `reuse`
- `filesFrom` (enum, required)
  - Allowed values: `payload`, `none`
- `title` (string, optional)

### TriggersPostResponsesContentApplicationJsonSchemaDataPermissions

- `runAsUserId` (string, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataLastRun

- `status` (enum, required)
  - Allowed values: `opened`, `busy`, `needs_input`, `blocked`, `error`
- `at` (datetime, required)
- `sessionId` (string, optional)
- `message` (string, optional)

### TriggersPostResponsesContentApplicationJsonSchemaDataLegacy

- `channelId` (string, optional)
- `channelType` (enum, optional)
  - Allowed values: `email`, `webhook`
- `automationId` (string, optional)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule

- TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule0
- TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule1

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen0

- TriggersPostResponsesContentApplicationJsonSchemaDataWhen00
- TriggersPostResponsesContentApplicationJsonSchemaDataWhen01
- TriggersPostResponsesContentApplicationJsonSchemaDataWhen02
- TriggersPostResponsesContentApplicationJsonSchemaDataWhen03

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen1

- `kind` ("webhook", required)
- `slug` (string, required)
- `secretPreview` (string, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataOpenSpacesItems

- `spaceId` (string, required)
- `access` (enum, required)
  - Allowed values: `read`, `commit`

### TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule0

- `kind` ("cron", required)
- `expression` (string, required)
- `timezone` (string, required)

### TriggersPostRequestBodyContentApplicationJsonSchemaWhenOneOf0Schedule1

- `kind` ("once", required)
- `at` (datetime, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen00

- `kind` ("schedule", required)
- `schedule` (TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen01

- `kind` ("email", required)
- `address` (string, required)
- `from` (list of string, optional)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen02

- `kind` ("webhook", required)
- `slug` (string, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhen03

- `kind` ("manual", required)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule

- TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule0
- TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule1

### TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule0

- `kind` ("cron", required)
- `expression` (string, required)
- `timezone` (string, required)

### TriggersPostResponsesContentApplicationJsonSchemaDataWhenOneOf0OneOf0Schedule1

- `kind` ("once", required)
- `at` (datetime, required)

## Examples

**Request**

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

**Response**

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

**SDK Code**

```python
import requests

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

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

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

print(response.json())
```

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

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

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

	payload := strings.NewReader("{\n  \"name\": \"string\",\n  \"when\": {\n    \"kind\": \"string\",\n    \"schedule\": {\n      \"expression\": \"string\",\n      \"kind\": \"string\",\n      \"timezone\": \"string\"\n    }\n  },\n  \"open\": {\n    \"agentIds\": [\n      \"string\"\n    ],\n    \"spaces\": [\n      {\n        \"spaceId\": \"string\",\n        \"access\": \"read\"\n      }\n    ],\n    \"instruction\": \"string\",\n    \"threadPolicy\": \"new\",\n    \"filesFrom\": \"payload\"\n  },\n  \"permissions\": {\n    \"runAsUserId\": \"string\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.cloudraker.com/triggers")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"string\",\n  \"when\": {\n    \"kind\": \"string\",\n    \"schedule\": {\n      \"expression\": \"string\",\n      \"kind\": \"string\",\n      \"timezone\": \"string\"\n    }\n  },\n  \"open\": {\n    \"agentIds\": [\n      \"string\"\n    ],\n    \"spaces\": [\n      {\n        \"spaceId\": \"string\",\n        \"access\": \"read\"\n      }\n    ],\n    \"instruction\": \"string\",\n    \"threadPolicy\": \"new\",\n    \"filesFrom\": \"payload\"\n  },\n  \"permissions\": {\n    \"runAsUserId\": \"string\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.cloudraker.com/triggers")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"string\",\n  \"when\": {\n    \"kind\": \"string\",\n    \"schedule\": {\n      \"expression\": \"string\",\n      \"kind\": \"string\",\n      \"timezone\": \"string\"\n    }\n  },\n  \"open\": {\n    \"agentIds\": [\n      \"string\"\n    ],\n    \"spaces\": [\n      {\n        \"spaceId\": \"string\",\n        \"access\": \"read\"\n      }\n    ],\n    \"instruction\": \"string\",\n    \"threadPolicy\": \"new\",\n    \"filesFrom\": \"payload\"\n  },\n  \"permissions\": {\n    \"runAsUserId\": \"string\"\n  }\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.cloudraker.com/triggers', [
  'body' => '{
  "name": "string",
  "when": {
    "kind": "string",
    "schedule": {
      "expression": "string",
      "kind": "string",
      "timezone": "string"
    }
  },
  "open": {
    "agentIds": [
      "string"
    ],
    "spaces": [
      {
        "spaceId": "string",
        "access": "read"
      }
    ],
    "instruction": "string",
    "threadPolicy": "new",
    "filesFrom": "payload"
  },
  "permissions": {
    "runAsUserId": "string"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.cloudraker.com/triggers");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"string\",\n  \"when\": {\n    \"kind\": \"string\",\n    \"schedule\": {\n      \"expression\": \"string\",\n      \"kind\": \"string\",\n      \"timezone\": \"string\"\n    }\n  },\n  \"open\": {\n    \"agentIds\": [\n      \"string\"\n    ],\n    \"spaces\": [\n      {\n        \"spaceId\": \"string\",\n        \"access\": \"read\"\n      }\n    ],\n    \"instruction\": \"string\",\n    \"threadPolicy\": \"new\",\n    \"filesFrom\": \"payload\"\n  },\n  \"permissions\": {\n    \"runAsUserId\": \"string\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "string",
  "when": [
    "kind": "string",
    "schedule": [
      "expression": "string",
      "kind": "string",
      "timezone": "string"
    ]
  ],
  "open": [
    "agentIds": ["string"],
    "spaces": [
      [
        "spaceId": "string",
        "access": "read"
      ]
    ],
    "instruction": "string",
    "threadPolicy": "new",
    "filesFrom": "payload"
  ],
  "permissions": ["runAsUserId": "string"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.cloudraker.com/triggers")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```