> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/sdks/scheduler/tasks/save-scheduler-task.md).

# Save Scheduler Task

Create or update a scheduled task.

A **scheduled task** sends an Email, SMS or Push campaign on a cron schedule, as a user you choose. This method creates a task (no `taskId`) or updates one (with `taskId`) and returns its id (`tsk_…`).

This method is on the **Hub** surface (`norbix.hub.scheduler`) — call it from admin tooling or IaC.

{% hint style="info" %}
**Email, SMS and Push campaign tasks.** `task.type` is `"EmailCampaign"`, `"SmsCampaign"` or `"PushCampaign"` (SMS and Push since 2026-10-05). `"CodeFunctionalCall"` and `"WebhookCall"` are known but refused (`CM-ERRORS-SCHEDULER-008`); a missing or unknown `type` is refused with `CM-ERRORS-SCHEDULER-007`.
{% endhint %}

**What every save needs**

| Field             | Example                                                                      | Notes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ----------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`            | `"Weekly newsletter"`                                                        | Required.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `cron`            | `"0 9 * * 1"`                                                                | Required. Exactly 5 fields (minute hour day-of-month month day-of-week), evaluated in **UTC**. Weekday `0`–`7`, both `0` and `7` are Sunday. A 6-field (seconds) expression is refused (`CM-ERRORS-SCHEDULER-006`).                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `initiatorUserId` | `"usr_2R5So1Lbfc7MNr5lkY522S"`                                               | Required. The user the task runs as: **you, or a service user of this project**. Another person is refused (`CM-ERRORS-SCHEDULER-010`), a user outside the project too (`-009`). A service user needs a role that may read the template and send the campaign, or every run fails (*Caller is missing required permission*).                                                                                                                                                                                                                                                                                                                                       |
| `isEnabled`       | `true`                                                                       | Send it on every save — the cron fires only while it is `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `stopOnError`     | `false`                                                                      | `true` disables the task the first time a run fails.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `task.type`       | `"EmailCampaign"`                                                            | `EmailCampaign`, `SmsCampaign` or `PushCampaign`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `task.campaign`   | `{ "source": "AllUsers", "templateId": "tmpl_…", "integrationId": "int_…" }` | The campaign to send, without a time. `templateId` and `integrationId` are required. **Email** — the shape of [Create Email Campaign](/codemash/sdks/notifications/email/create-email-campaign.md): `source` is `AllUsers` (optional `rolesNames` = role **ids** `pr_…_nr_…`, `userTags`), `SpecifiedUsers` (`userRecipients`) or `Email` (`recipients`). **Push** — `source` (`AllUsers`, `SpecifiedUsers`, `Devices`, …) and its recipients. **SMS** — the flat SMS campaign body: `deliveryType` (for example `PhoneNumbers`) and the block of that name, for example `phoneNumbers: { recipientsSourceType: 'PhoneNumbers', phoneNumbers: ['+15555550123'] }`. |
| `taskId`          | `"tsk_2JRW9lGpUBbcfvi5mcFW7o"`                                               | Only to update an existing task. A save replaces the whole task: send every field again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

Creating needs the `scheduler:create` permission, updating `scheduler:update`. The Scheduler module must be on.

{% hint style="info" %}
These examples assume the SDK is installed and your credentials are set as environment variables — each client reads them automatically, so the constructors below take no arguments. See [Install a Norbix SDK](/codemash/sdks/install.md).
{% endhint %}

{% tabs %}
{% tab title="JavaScript / TypeScript" %}

```ts
import { Norbix } from '@norbix.ai/ts';
const norbix = new Norbix();

const result = await norbix.hub.scheduler.saveSchedulerTask({
  name: 'Weekly newsletter',
  cron: '0 9 * * 1',                                // Mondays 09:00 UTC
  initiatorUserId: 'usr_2R5So1Lbfc7MNr5lkY522S', // you or a service user
  isEnabled: true,
  stopOnError: false,
  task: {
    type: 'EmailCampaign',
    campaign: {
      source: 'AllUsers',
      templateId: 'tmpl_ZCPg9Nb2Nh2P4bLrUEOBh',
      integrationId: 'int_4dotEqXT1UolAf5w6FqcMT',
      rolesNames: ['pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA'], // role ids
    },
  },
});
// SMS:  task: { type: 'SmsCampaign', campaign: { deliveryType: 'PhoneNumbers', templateId: 'tmpl_…', integrationId: 'int_…',
//         phoneNumbers: { recipientsSourceType: 'PhoneNumbers', phoneNumbers: ['+15555550123'] } } }
// Push: task: { type: 'PushCampaign', campaign: { source: 'AllUsers', templateId: 'tmpl_…', integrationId: 'int_…' } }
// result.id → 'tsk_…'
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Norbix.Sdk;
using Norbix.Sdk.Types.Hub;

using var client = new NorbixClient();

// Needs a Norbix.Hub version with the typed email task (EmailCampaignSchedulerTaskRequest).
var result = await client.Scheduler.SaveSchedulerTaskAsync(new SaveSchedulerTaskRequest
{
    Name = "Weekly newsletter",
    Cron = "0 9 * * 1",                               // Mondays 09:00 UTC
    InitiatorUserId = "usr_2R5So1Lbfc7MNr5lkY522S", // you or a service user
    IsEnabled = true,
    StopOnError = false,
    Task = new EmailCampaignSchedulerTaskRequest
    {
        Type = SchedulerTaskType.EmailCampaign,
        Campaign = new EmailToAllUsersDeliverySettingsRequest
        {
            Source = EmailCampaignRecipientsSourceTypes.AllUsers,
            TemplateId = "tmpl_ZCPg9Nb2Nh2P4bLrUEOBh",
            IntegrationId = "int_4dotEqXT1UolAf5w6FqcMT",
            RolesNames = ["pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA"],
        },
    },
});
```

{% endtab %}

{% tab title="Python" %}

```python
from norbix_python import NorbixHub

norbix = NorbixHub()

result = norbix.scheduler.save_scheduler_task(
    name="Weekly newsletter",
    cron="0 9 * * 1",                               # Mondays 09:00 UTC
    initiatorUserId="usr_2R5So1Lbfc7MNr5lkY522S", # you or a service user
    isEnabled=True,
    stopOnError=False,
    task={
        "type": "EmailCampaign",
        "campaign": {
            "source": "AllUsers",
            "templateId": "tmpl_ZCPg9Nb2Nh2P4bLrUEOBh",
            "integrationId": "int_4dotEqXT1UolAf5w6FqcMT",
            "rolesNames": ["pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA"],
        },
    },
)
```

{% endtab %}

{% tab title="Go" %}

```go
c, _ := norbix.New(norbix.Options{})
ctx := context.Background()

var result map[string]any
err := c.Hub.Scheduler.SaveSchedulerTask(ctx, map[string]any{
	"name":            "Weekly newsletter",
	"cron":            "0 9 * * 1", // Mondays 09:00 UTC
	"initiatorUserId": "usr_2R5So1Lbfc7MNr5lkY522S",
	"isEnabled":       true,
	"stopOnError":     false,
	"task": map[string]any{
		"type": "EmailCampaign",
		"campaign": map[string]any{
			"source":     "AllUsers",
			"templateId":    "tmpl_ZCPg9Nb2Nh2P4bLrUEOBh",
			"integrationId": "int_4dotEqXT1UolAf5w6FqcMT",
			"rolesNames":    []string{"pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA"},
		},
	},
}, &result)
```

{% endtab %}

{% tab title="Dart / Flutter" %}

```dart
import 'package:norbix/norbix_hub.dart';

final hub = NorbixHub();

final result = await hub.scheduler.saveSchedulerTask(body: {
  'name': 'Weekly newsletter',
  'cron': '0 9 * * 1',
  'initiatorUserId': 'usr_2R5So1Lbfc7MNr5lkY522S',
  'isEnabled': true,
  'stopOnError': false,
  'task': {
    'type': 'EmailCampaign',
    'campaign': {
      'source': 'AllUsers',
      'templateId': 'tmpl_ZCPg9Nb2Nh2P4bLrUEOBh',
      'integrationId': 'int_4dotEqXT1UolAf5w6FqcMT',
      'rolesNames': ['pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA'],
    },
  },
});
```

{% endtab %}

{% tab title="Swift" %}

```swift
import NorbixHub

let client = try NorbixHubClient()

let result = try await client.scheduler.saveSchedulerTask([
    "name": "Weekly newsletter",
    "cron": "0 9 * * 1",
    "initiatorUserId": "usr_2R5So1Lbfc7MNr5lkY522S",
    "isEnabled": true,
    "stopOnError": false,
    "task": [
        "type": "EmailCampaign",
        "campaign": [
            "source": "AllUsers",
            "templateId": "tmpl_ZCPg9Nb2Nh2P4bLrUEOBh",
            "integrationId": "int_4dotEqXT1UolAf5w6FqcMT",
            "rolesNames": ["pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA"],
        ],
    ],
])
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import ai.norbix.sdk.hub.NorbixHub

val hub = NorbixHub()

val result = hub.scheduler.saveSchedulerTask(mapOf(
    "name" to "Weekly newsletter",
    "cron" to "0 9 * * 1",
    "initiatorUserId" to "usr_2R5So1Lbfc7MNr5lkY522S",
    "isEnabled" to true,
    "stopOnError" to false,
    "task" to mapOf(
        "type" to "EmailCampaign",
        "campaign" to mapOf(
            "source" to "AllUsers",
            "templateId" to "tmpl_ZCPg9Nb2Nh2P4bLrUEOBh",
            "integrationId" to "int_4dotEqXT1UolAf5w6FqcMT",
            "rolesNames" to listOf("pr_7ZX0qmmXY0AoSXi9GAITtr_nr_6UZJSs5Dbki0HL4kHOyfxA"),
        ),
    ),
))
```

{% endtab %}

{% tab title="CLI" %}

```sh
norbix hub scheduler task save --name 'Weekly newsletter' --cron '0 9 * * 1' \
  --initiatorUserId usr_2R5So1Lbfc7MNr5lkY522S --isEnabled true --stopOnError false \
  --task:json '{"type":"EmailCampaign","campaign":{"source":"Email","recipients":["news@example.com"],"templateId":"tmpl_ZCPg9Nb2Nh2P4bLrUEOBh","integrationId":"int_4dotEqXT1UolAf5w6FqcMT"}}'
# update: add --taskId tsk_… and send every field again (the server replaces the task)
# shorter: norbix scheduler save --name 'Weekly newsletter' --cron '0 9 * * 1' --initiator usr_2R5So1Lbfc7MNr5lkY522S \
#   --template tmpl_ZCPg9Nb2Nh2P4bLrUEOBh --audience emails --email news@example.com --integration int_4dotEqXT1UolAf5w6FqcMT --enabled
```

{% endtab %}
{% endtabs %}

## In Cloud

Manage this visually in Cloud — see [Create a task](/codemash/cloud/tasks/tasks/new.md).

## API reference

Full request and response for this endpoint: [Save Scheduler Task](/codemash/api-reference/scheduler/tasks/save-scheduler-task.md).
