Skip to main content
Skip to main content

Notifications

Queries and Mutations listed here are used to send requests to the Admin Notification API Routes.

All hooks listed 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.

Mutations

useAdminResendNotification

This hook resends a previously sent notifications, with the same data but optionally to a different address.

Example

import React from "react"
import { useAdminResendNotification } from "medusa-react"

type Props = {
notificationId: string
}

const Notification = ({ notificationId }: Props) => {
const resendNotification = useAdminResendNotification(
notificationId
)
// ...

const handleResend = () => {
resendNotification.mutate({}, {
onSuccess: ({ notification }) => {
console.log(notification.id)
}
})
}

// ...
}

export default Notification

Hook Parameters

idstringRequired
The ID of the notification.

Mutation Function Parameters

AdminPostNotificationsNotificationResendReqAdminPostNotificationsNotificationResendReqRequired
The resend details.

Mutation Function Returned Data

AdminNotificationsResAdminNotificationsResRequired
The notification's details.

Queries

useAdminNotifications

This hook retrieves 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 React from "react"
import { useAdminNotifications } from "medusa-react"

const Notifications = () => {
const { notifications, isLoading } = useAdminNotifications()

return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}

export default Notifications

To specify relations that should be retrieved within the notifications:

import React from "react"
import { useAdminNotifications } from "medusa-react"

const Notifications = () => {
const { notifications, isLoading } = useAdminNotifications({
expand: "provider"
})

return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}

export default Notifications

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

import React from "react"
import { useAdminNotifications } from "medusa-react"

const Notifications = () => {
const {
notifications,
limit,
offset,
isLoading
} = useAdminNotifications({
expand: "provider",
limit: 20,
offset: 0
})

return (
<div>
{isLoading && <span>Loading...</span>}
{notifications && !notifications.length && (
<span>No Notifications</span>
)}
{notifications && notifications.length > 0 && (
<ul>
{notifications.map((notification) => (
<li key={notification.id}>{notification.to}</li>
))}
</ul>
)}
</div>
)
}

export default Notifications

Hook Parameters

Filters and pagination configurations applied to the retrieved notifications.

Query Returned Data

limitnumberRequired
The limit applied on the retrieved items.
offsetnumberRequired
The number of items skipped before retrieving the list of items.
countnumberRequired
The total count of items.
notificationsNotification[]Required
an array of notifications
Was this section helpful?