# Notifications

## Create a notification

Notifications are created for individual users, a notification will be sent as a push notification to each of the user's registered devices.

{% hint style="info" %}
If the user doesn't have configured any devices, the notification will still be created but not marked as sent.
{% endhint %}

The Extra Horizon SDK can be used to create a notification as follows:

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

```javascript
const notification = await exh.notificationsV2.create({
  targetUserId: userId,
  title: 'Hello from Extra Horizon',
  descriptions: 'Welcome to our platform'
});

console.log('Notification was created with id:', notification.id);
console.log('Notification was sent to a device:', notification.sent);
```

{% endtab %}
{% endtabs %}

## List notifications

There are multiple methods available in the SDK at `exh.notificationsV2` to fetch notifications.

For example, getting a specific notification by its id:

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

```javascript
const notification = await exh.notificationsV2.findById(notificationId);
console.log('Notification was sent to:', notification.targetUserId);
```

{% endtab %}
{% endtabs %}

Or, list notifications for a specific user:

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

```javascript
const response = await exh.notificationsV2.findByTargetUserId(userId);
console.log('Notifications:', response.data);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.extrahorizon.com/extrahorizon/services/communication/notification-service/notifications.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
