# Create a trigger

> Source: https://docs.clonepartner.com/api-reference/triggers/create-trigger/

`POST /api/triggers`

Create a trigger

**Operation ID:** `createTrigger`

## Authentication

### Option 1

- **BearerAuth** (`http bearer`)
  API key token. Create via POST /api/api-keys. Format: `envoy_<hex>`

### Option 2

- **CookieAuth** (`apiKey`)
  Session cookie set after login + TOTP verification

## Request body

The request body is required.

### `application/json`

- Type: `object`
- Properties:
  - `job_id` (`integer`, `required`)
  - `task_key` (`string`) — Specific task key within the job to trigger
  - `type` (`string`)
    - Allowed values: `cron`, `one_off`
    - Default: `cron`
  - `cron_expression` (`string`) — Cron expression (e.g. '0 */6 * * *') for type=cron; ISO-8601 datetime (UTC) in the future for type=one_off.
  - `arguments` (`object`)
    - Additional properties: allowed
  - `enabled` (`boolean`)
    - Default: `true`

## Success responses

### 201

Trigger created

**Content type:** `application/json`

- Reference: `Trigger`
  - Type: `object`
  - Properties:
    - `id` (`integer`)
    - `job_id` (`integer`)
    - `task_key` (`string | null`)
      - Nullable: yes
    - `type` (`string`) — cron repeats on a cron expression; one_off fires once at the datetime in cron_expression then auto-disables.
      - Description: cron repeats on a cron expression; one_off fires once at the datetime in cron_expression then auto-disables.
      - Allowed values: `cron`, `one_off`
    - `cron_expression` (`string | null`) — 5-field cron expression for type=cron; ISO-8601 datetime (UTC) for type=one_off.
      - Description: 5-field cron expression for type=cron; ISO-8601 datetime (UTC) for type=one_off.
      - Nullable: yes
    - `arguments` (`string | null`) — JSON-encoded arguments
      - Description: JSON-encoded arguments
      - Nullable: yes
    - `enabled` (`integer`)
      - Allowed values: `0`, `1`
    - `last_triggered_at` (`string | null`)
      - Format: `date-time`
      - Nullable: yes
    - `created_at` (`string`)
      - Format: `date-time`
    - `updated_at` (`string`)
      - Format: `date-time`

## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/triggers' \
  --header 'Authorization: Bearer $API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "job_id": 0
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/triggers', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "job_id": 0
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
