> For the complete documentation index, see [llms.txt](https://docs.codemash.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codemash.io/sdks-and-cli/database/triggers/save-schema-trigger.md).

# Save Schema Trigger

A **schema trigger** runs an action automatically when records change in a collection — for example emailing the team when a record is inserted, or calling a webhook when one is deleted. It watches one schema (set `schemaId`) and fires on `OnInserted`, `OnUpdated`, or `OnDeleted`. This method creates the trigger (or updates it when you pass an existing `triggerId`); the response returns its id.

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

{% 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](/sdks-and-cli/install.md).
{% endhint %}

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

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

const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'notify-on-insert',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'email',
      templateId: 'tmpl_5XqvoF4k6I2GfarDBg3zqq',
      deliverySettings: { recipientsSourceType: 'AllUsers' },
    },
  },
});
```

{% endtab %}

{% tab title=".NET" %}

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

using var client = new NorbixClient();

var result = await client.Database.SaveSchemaTriggerAsync(new SaveSchemaTrigger
{
    Trigger = new SchemaTriggerRequest
    {
        Type = TriggerType.Schema,
        When = SchemaTriggerType.OnInserted,
        Name = "notify-on-insert",
        IsEnabled = true,
        SchemaId = "sch_6q37t61LzEQQBWDaRfJ8JS",
        Action = new TriggerActionEmailDto
        {
            Type = TriggerActionType.Email,
            TemplateId = "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            DeliverySettings = new EmailToAllUsersDeliverySettingsDto
            {
                RecipientsSourceType = EmailCampaignRecipientsSourceTypes.AllUsers,
            },
        },
    },
});
```

{% endtab %}

{% tab title="Python" %}

```python
from norbix_python import NorbixHub

norbix = NorbixHub()

result = norbix.database.save_schema_trigger(
    trigger={
        "type": "Schema",
        "when": "OnInserted",
        "name": "notify-on-insert",
        "isEnabled": True,
        "schemaId": "sch_6q37t61LzEQQBWDaRfJ8JS",
        "action": {
            "type": "email",
            "templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings": {"recipientsSourceType": "AllUsers"},
        },
    },
)
```

{% endtab %}

{% tab title="Go" %}

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

var result map[string]any
err := c.Hub.Database.SaveSchemaTrigger(ctx, map[string]any{
	"trigger": map[string]any{
		"type": "Schema",
		"when": "OnInserted",
		"name": "notify-on-insert",
		"isEnabled": true,
		"schemaId": "sch_6q37t61LzEQQBWDaRfJ8JS",
		"action": map[string]any{
			"type": "email",
			"templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
			"deliverySettings": map[string]any{"recipientsSourceType": "AllUsers"},
		},
	},
}, &result)
```

{% endtab %}

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

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

final hub = NorbixHub();

final result = await hub.database.saveSchemaTrigger(body: {
  'trigger': {
    'type': 'Schema',
    'when': 'OnInserted',
    'name': 'notify-on-insert',
    'isEnabled': true,
    'schemaId': 'sch_6q37t61LzEQQBWDaRfJ8JS',
    'action': {
      'type': 'email',
      'templateId': 'tmpl_5XqvoF4k6I2GfarDBg3zqq',
      'deliverySettings': {'recipientsSourceType': 'AllUsers'},
    },
  },
});
```

{% endtab %}

{% tab title="Swift" %}

```swift
import NorbixSwift

let client = Norbix()

let result = try await client.hub.database.saveSchemaTrigger([
    "trigger": [
        "type": "Schema",
        "when": "OnInserted",
        "name": "notify-on-insert",
        "isEnabled": true,
        "schemaId": "sch_6q37t61LzEQQBWDaRfJ8JS",
        "action": [
            "type": "email",
            "templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings": ["recipientsSourceType": "AllUsers"],
        ],
    ],
])
```

{% endtab %}

{% tab title="Kotlin" %}

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

val hub = NorbixHub()

val result = hub.database.saveSchemaTrigger(mapOf(
    "trigger" to mapOf(
        "type" to "Schema",
        "when" to "OnInserted",
        "name" to "notify-on-insert",
        "isEnabled" to true,
        "schemaId" to "sch_6q37t61LzEQQBWDaRfJ8JS",
        "action" to mapOf(
            "type" to "email",
            "templateId" to "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings" to mapOf("recipientsSourceType" to "AllUsers"),
        ),
    ),
))
```

{% endtab %}

{% tab title="CLI" %}

```sh
norbix raw '/{version}/database/schemas/triggers' -X POST --body '{"trigger":{"type":"Schema","when":"OnInserted","name":"notify-on-insert","isEnabled":true,"schemaId":"sch_6q37t61LzEQQBWDaRfJ8JS","action":{"type":"email","templateId":"tmpl_5XqvoF4k6I2GfarDBg3zqq","deliverySettings":{"recipientsSourceType":"AllUsers"}}}}'
```

{% endtab %}
{% endtabs %}

## Scenarios

The examples above send an email to all users. The `action` object is where the behaviour lives — here is one working example for **every** action type (JavaScript; the structure is identical in the other SDKs, only syntax changes as in the tabs above).

### Email specific users

Send a templated email to chosen project users when a record is inserted.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'email-team',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'email',
      templateId: 'tmpl_3bJqQKtPFWfYpVSYnsN3mn',
      deliverySettings: {
        recipientsSourceType: 'SpecifiedUsers',
        userRecipients: ['usr_5hoyo3ThWet5Ik9nc8i8ni', 'usr_3IzD37jxlmrmVhUs9wa7BC'],
      },
    },
  },
});
```

### Email raw addresses

Send the email to fixed addresses (an ops inbox, an external partner) instead of project users.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'email-ops',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'email',
      templateId: 'tmpl_3bJqQKtPFWfYpVSYnsN3mn',
      deliverySettings: {
        recipientsSourceType: 'Email',
        recipients: ['ops@example.com'],
      },
    },
  },
});
```

### Push notification to all users

Send a mobile push from a push template to every user when a record is inserted.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'push-announce',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'push',
      templateId: 'tmpl_1mq9lRiNGCKMST1hiEQ74M',
      deliverySettings: { recipientsSourceType: 'AllUsers' },
    },
  },
});
```

### SMS to phone numbers

Send a text message to fixed phone numbers.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'sms-oncall',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'sms',
      templateId: 'tmpl_25aiVcKJGOyZmO58pedIeX',
      deliverySettings: {
        recipientsSourceType: 'PhoneNumbers',
        phoneNumbers: ['+14155550123'],
      },
    },
  },
});
```

### Call a webhook

Publish the event to your configured webhook destinations. Destinations (URLs, secrets) are managed in the Webhooks module; here you only pick which ones receive it.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'webhook-crm',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'webhookcall',
      deliverySettings: { destinationIds: ['whd_5K6DoEHqml6S0sa7fNuHIQ'] },
    },
  },
});
```

### Run a function

Execute one of your functions from the Code module with the event as input.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'run-function',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'code',
      functionId: 'cf_3VXuCiv7paJwQHkKTFWrVq',
      deliverySettings: {},
    },
  },
});
```

### Send a realtime (SSE) event

Push a server-sent event to connected clients — for live UI updates.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'realtime-update',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'ssecall',
      deliverySettings: {
        audience: 'ToCurrentUser',
        eventName: 'entity.changed',
      },
    },
  },
});
```

### Run a marketplace function

Fire an installed marketplace function; `payload` passes extra static values.

```ts
const result = await norbix.hub.database.saveSchemaTrigger({
  trigger: {
    type: 'Schema',
    when: 'OnInserted',
    name: 'marketplace-sync',
    isEnabled: true,
    schemaId: 'sch_6q37t61LzEQQBWDaRfJ8JS',
    action: {
      type: 'marketplace',
      functionId: 'func_4f3VoJJV9ayAellzC9o58T',
      payload: { plan: 'pro' },
    },
  },
});
```

For every field of every shape (CC/BCC, campaign timing, timezone settings, token mappings, collection-based audiences), see the [API reference](/api-reference/database/schemas/save-schema-trigger.md). More runnable examples live in the SDK repos on [GitHub](https://github.com/norbix-code).

## In the dashboard

Manage this visually in Norbix Cloud — see [Database → Collections → Triggers](/norbix-cloud/database/collections/triggers.md).

## API reference

Full request and response for this endpoint: [Save Schema Trigger](/api-reference/database/schemas/save-schema-trigger.md).
