> For the complete documentation index, see [llms.txt](https://api.dataloy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.dataloy.com/user-guides/enterprise-functionality/subscribe-a-user-to-an-alert.md).

# Subscribe a User to an Alert

You can subscribe a user to an alert through the API. This works the same way as subscribing from **Notification Settings** in the VMS client.

> **Note:** After you subscribe a user through the API, they have to refresh the page or log in again before notifications show up in the VMS client.

### Channels

| Channel       | `channelType` | `url`                   |
| ------------- | ------------- | ----------------------- |
| In-app (push) | `WSOC`        | `"."`                   |
| Email         | `EMAIL`       | Recipient email address |

### Subscribe

Before you create a new subscription, check whether the user already has an unsubscribed one (see Resubscribe). If they do, reactivate it instead of creating a duplicate.

`POST ws/rest/WebhookSubscription`

#### In-app (WSOC)

```json
{
    "channelInfo": {
        "channelType": "WSOC",
        "httpRequestParams": [],
        "url": "."
    },
    "dlpAlertScript": "KSS",
    "expression": null,
    "isScheduled": false,
    "onlyMainObject": false,
    "templateMsg": null,
    "unsubscribed": false,
    "user": { "key": 999999 },
    "webhookTemplate": "KSS",
    "accessToken": null
}
```

#### Email

```json
{
    "channelInfo": {
        "channelType": "EMAIL",
        "httpRequestParams": [],
        "url": "test@dataloy.com"
    },
    "dlpAlertScript": "KSS",
    "expression": null,
    "isScheduled": false,
    "onlyMainObject": false,
    "templateMsg": null,
    "unsubscribed": false,
    "user": { "key": 999999 },
    "webhookTemplate": "KSS",
    "accessToken": null
}
```

| Field             | Name in the client | Description                                                                                                                                                                                                                                      |
| ----------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `user.key`        | User               | Key of the user to subscribe                                                                                                                                                                                                                     |
| `webhookTemplate` | Webhook Alerts     | The alert to subscribe to                                                                                                                                                                                                                        |
| `dlpAlertScript`  | Alert Scripts      | The alert script used by the alert                                                                                                                                                                                                               |
| `isScheduled`     | Custom Schedule    | `true` to also run the alert on a schedule. The alert script's triggers still fire on data changes. Requires `webhookSchedule`, see [Webhooks - New functionalities](/dataloy-rest-api/webhooks/webhooks-new-functionalities.md#custom-schedule) |

> **Note:** The examples reference `webhookTemplate` and `dlpAlertScript` by **code** (`"KSS"`). You can also reference them by **key**, e.g. `"webhookTemplate": { "key": 123 }`.

### Find a subscription

Both unsubscribe and resubscribe need the subscription `key`. To find it, filter on channel, user and template:

`GET ws/rest/WebhookSubscription?filter=channelInfo.channelType.channelTypeCode(EQ){channel}&filter=user.key(EQ){userKey}&filter=webhookTemplate.key(EQ){templateKey}&filter=unsubscriptionDate({NULL|NOTNULL})`

* `unsubscriptionDate(NULL)`: active subscriptions
* `unsubscriptionDate(NOTNULL)`: unsubscribed subscriptions

### Unsubscribe

Find the **active** subscription (`unsubscriptionDate(NULL)`), then update it:

`PUT ws/rest/WebhookSubscription/{key}`

```json
{
    "unsubscribed": true
}
```

### Resubscribe

Find the **unsubscribed** subscription (`unsubscriptionDate(NOTNULL)`), then update it:

`PUT ws/rest/WebhookSubscription/{key}`

```json
{
    "unsubscribed": false
}
```

If no unsubscribed subscription exists, create a new one as described in Subscribe.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://api.dataloy.com/user-guides/enterprise-functionality/subscribe-a-user-to-an-alert.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
