4.4.1. Event Data Payload

In this chapter, you'll learn how subscribers receive an event's data payload.

Access Event's Data Payload#

When events are emitted, they’re emitted with a data payload.

The object that the subscriber function receives as a parameter has a data property, which is an object holding the event payload with additional context.

For example:

src/subscribers/product-created.ts
4} from "@medusajs/medusa"5
6export default async function productCreateHandler({7  data,8}: SubscriberArgs<{ id: string }>) {9  const productId = data.data.id10  console.log(`The product ${productId} was created`)11}12
13export const config: SubscriberConfig = {14  event: "product.created",15}

The data object has the following properties:

dataobject
The data payload of the event. Its properties depend on the event.
eventNamestring
The name of the triggered event.
metadataobject
Additional data and context of the emitted event.

This logs the product ID received in the product.created event’s data payload to the console.


List of Events with Data Payload#

Refer to this reference for a full list of events emitted by Medusa and their data payloads.

Was this chapter helpful?