Skip to main content
Skip to main content

AdminNotificationsResource

This class is used to send requests to Admin Notification API Routes. All its method are available in the JS Client under the medusa.admin.notifications property.

All methods in this class require authentication.

Notifications are sent to customers to inform them of new updates. For example, a notification can be sent to the customer when their order is place or its state is updated. The notification's type, such as an email or SMS, is determined by the notification provider installed on the Medusa backend.

Methods

list

Retrieve a list of notifications. The notifications can be filtered by fields such as event_name or resource_type passed in the query parameter. The notifications can also be paginated.

Example

To list notifications:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.notifications.list()
.then(({ notifications }) => {
console.log(notifications.length);
})

To specify relations that should be retrieved within the notifications:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.notifications.list({
expand: "provider"
})
.then(({ notifications }) => {
console.log(notifications.length);
})

By default, only the first 50 records are retrieved. You can control pagination by specifying the limit and offset properties:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.notifications.list({
expand: "provider",
limit,
offset
})
.then(({ notifications }) => {
console.log(notifications.length);
})

Parameters

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Filters and pagination configurations applied to the retrieved notifications.

Returns

ResponsePromiseResponsePromise<AdminNotificationsListRes>Required
Resolves to the list of notifications with pagination fields.

resend

Resend a previously sent notifications, with the same data but optionally to a different address.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.notifications.resend(notificationId)
.then(({ notification }) => {
console.log(notification.id);
})

Parameters

idstringRequired
The notification's ID.
The details necessary to resend the notification.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminNotificationsRes>Required
Resolves to the notification's details.
Was this section helpful?