# Create

Create a new scheduled job that posts to Slack or Discord on a cron schedule.





<Callout type="info">
  You'll need a platform `channel_id` from [Channels](/api/channels/list) to create a scheduled job. Pass that `channel_id` (for example `C09M8FRJYTF` for Slack, or the numeric snowflake for Discord) as `connected_channel_id`, **not** the internal `cc_…` record ID.
</Callout>

See [Schedule rules](/api/scheduled-jobs/schedule-rules) for cron format and timezone requirements.

```http
POST /api/public/v1/scheduled-jobs
```

## Request body [#request-body]

<TypeTable
  type="{
  schedule: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;5-field cron expression (for example `0 9 * * *` for daily at 9am). Minimum granularity is 5 minutes.&#x22;
  },
  timezone: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;IANA timezone (for example `America/New_York`, `UTC`).&#x22;
  },
  prompt: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;The prompt to execute on schedule.&#x22;
  },
  connected_channel_id: {
    type: &#x22;string&#x22;,
    description: &#x22;Platform `channel_id` of the connected Slack or Discord channel (for example `C09M8FRJYTF` for Slack, or the numeric snowflake for Discord). Discover via `GET /connected-channels`. **Required when `job_type` is `slack` or `discord`. Omitted/ignored when `job_type` is `app`.**&#x22;
  },
  job_type: {
    type: &#x22;string&#x22;,
    required: true,
    description: &#x22;One of `slack`, `discord`, or `app`. `slack`/`discord` must match the connected channel's `channel_type`. Use `app` to schedule a prompt against an in-app agent conversation (no Slack/Discord channel required — see `agent_id` below).&#x22;
  },
  agent_id: {
    type: &#x22;string&#x22;,
    description: &#x22;Only used when `job_type=app`. Selects which agent runs the scheduled prompt. Accepts either the ULID (`cci_...`) or the agent slug.&#x22;
  },
  is_threaded: {
    type: &#x22;boolean&#x22;,
    default: &#x22;false&#x22;,
    description: &#x22;Whether to post results in a thread.&#x22;
  },
  is_enabled: {
    type: &#x22;boolean&#x22;,
    default: &#x22;false&#x22;,
    description: &#x22;Whether the job is active.&#x22;
  }
}"
/>

## Example [#example]

<Tabs items="[&#x22;bash&#x22;, &#x22;TypeScript&#x22;, &#x22;Ruby&#x22;, &#x22;Python&#x22;, &#x22;Go&#x22;]">
  <Tab value="bash">
    ```bash
    curl -X POST https://api.nairi.ai/api/public/v1/scheduled-jobs \
      -H "Authorization: Bearer $NAIRI_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "schedule": "0 9 * * *",
        "timezone": "America/New_York",
        "prompt": "Generate daily status report",
        "connected_channel_id": "C09M8FRJYTF",
        "job_type": "slack",
        "is_threaded": true,
        "is_enabled": true
      }'
    ```
  </Tab>

  <Tab value="TypeScript">
    ```ts
    const res = await fetch("https://api.nairi.ai/api/public/v1/scheduled-jobs", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.NAIRI_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        schedule: "0 9 * * *",
        timezone: "America/New_York",
        prompt: "Generate daily status report",
        connected_channel_id: "C09M8FRJYTF",
        job_type: "slack",
        is_threaded: true,
        is_enabled: true,
      }),
    });
    const data = (await res.json()) as { id: string };
    ```
  </Tab>

  <Tab value="Ruby">
    ```ruby
    require "net/http"
    require "json"
    require "uri"

    uri = URI("https://api.nairi.ai/api/public/v1/scheduled-jobs")
    req = Net::HTTP::Post.new(uri)
    req["Authorization"] = "Bearer #{ENV['NAIRI_API_KEY']}"
    req["Content-Type"] = "application/json"
    req.body = {
      schedule: "0 9 * * *",
      timezone: "America/New_York",
      prompt: "Generate daily status report",
      connected_channel_id: "C09M8FRJYTF",
      job_type: "slack",
      is_threaded: true,
      is_enabled: true,
    }.to_json

    res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
    data = JSON.parse(res.body)
    ```
  </Tab>

  <Tab value="Python">
    ```python
    import os
    import requests

    res = requests.post(
        "https://api.nairi.ai/api/public/v1/scheduled-jobs",
        headers={
            "Authorization": f"Bearer {os.environ['NAIRI_API_KEY']}",
            "Content-Type": "application/json",
        },
        json={
            "schedule": "0 9 * * *",
            "timezone": "America/New_York",
            "prompt": "Generate daily status report",
            "connected_channel_id": "C09M8FRJYTF",
            "job_type": "slack",
            "is_threaded": True,
            "is_enabled": True,
        },
    )
    data = res.json()
    ```
  </Tab>

  <Tab value="Go">
    ```go
    package main

    import (
    	"bytes"
    	"encoding/json"
    	"fmt"
    	"io"
    	"net/http"
    	"os"
    )

    func main() {
    	body, _ := json.Marshal(map[string]any{
    		"schedule":             "0 9 * * *",
    		"timezone":             "America/New_York",
    		"prompt":               "Generate daily status report",
    		"connected_channel_id": "C09M8FRJYTF",
    		"job_type":             "slack",
    		"is_threaded":          true,
    		"is_enabled":           true,
    	})
    	req, _ := http.NewRequest("POST", "https://api.nairi.ai/api/public/v1/scheduled-jobs", bytes.NewReader(body))
    	req.Header.Set("Authorization", "Bearer "+os.Getenv("NAIRI_API_KEY"))
    	req.Header.Set("Content-Type", "application/json")
    	res, _ := http.DefaultClient.Do(req)
    	defer res.Body.Close()
    	raw, _ := io.ReadAll(res.Body)
    	var data map[string]any
    	json.Unmarshal(raw, &data)
    	fmt.Println(data)
    }
    ```
  </Tab>
</Tabs>

## Response: `201 Created` [#response-201-created]

```json
{
  "id": "sj_01K7XSRBBM0294N1WBD2M9EVQC",
  "schedule": "0 9 * * *",
  "timezone": "America/New_York",
  "prompt": "Generate daily status report",
  "connected_channel_id": "C09M8FRJYTF",
  "job_type": "slack",
  "is_threaded": true,
  "is_enabled": true,
  "last_executed_at": "2026-04-12T18:45:12.000Z",
  "created_at": "2026-04-12T18:45:12.000Z",
  "updated_at": "2026-04-12T18:45:12.000Z"
}
```

<Callout type="info">
  On create, `last_executed_at` is set to creation time (not null), even when `is_enabled` is `false`. This prevents the job from firing immediately the moment it is enabled.
</Callout>
