Send Notification with the Notification Module

In this guide, you'll learn about the different ways to send notifications using the Notification Module.

Using the Create Method#

In your resource, such as a subscriber, resolve the Notification Module's main service and use its create method:

src/subscribers/product-created.ts
6import { INotificationModuleService } from "@medusajs/framework/types"7
8export default async function productCreateHandler({9  event: { data },10  container,11}: SubscriberArgs<{ id: string }>) {12  const notificationModuleService: INotificationModuleService =13    container.resolve(Modules.NOTIFICATION)14
15  await notificationModuleService.createNotifications({16    to: "user@gmail.com",17    channel: "email",18    template: "product-created",19    data,20  })21}22
23export const config: SubscriberConfig = {24  event: "product.created",25}

The create method accepts an object or an array of objects having the following properties:

Loading...

For a full list of properties accepted, refer to this guide.


Using the sendNotificationsStep#

If you want to send a notification as part of a workflow, You can use the sendNotificationsStep in your workflow.

For example:

src/workflows/send-email.ts
1import { createWorkflow } from "@medusajs/framework/workflows-sdk"2import { 3  sendNotificationsStep, 4  useQueryGraphStep,5} from "@medusajs/medusa/core-flows"6
7type WorkflowInput = {8  id: string9}10
11export const sendEmailWorkflow = createWorkflow(12  "send-email-workflow",13  ({ id }: WorkflowInput) => {14    const { data: products } = useQueryGraphStep({15      entity: "product",16      fields: [17        "*",18        "variants.*",19      ],20      filters: {21        id,22      },23    })24
25    sendNotificationsStep({26      to: "user@gmail.com",27      channel: "email",28      template: "product-created",29      data: {30        product_title: product[0].title,31        product_image: product[0].images[0]?.url,32      },33    })34  }35)

For a full list of input properties accepted, refer to the sendNotificationsStep reference.

You can then execute this workflow in a subscriber, API route, or scheduled job.

For example, you can execute it when a product is created:

src/subscribers/product-created.ts
1import type {2  SubscriberArgs,3  SubscriberConfig,4} from "@medusajs/framework"5import { sendEmailWorkflow } from "../workflows/send-email"6
7export default async function productCreateHandler({8  event: { data },9  container,10}: SubscriberArgs<{ id: string }>) {11  await sendEmailWorkflow(container).run({12    input: {13      id: data.id,14    },15  })16}17
18export const config: SubscriberConfig = {19  event: "product.created",20}
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break