4.9.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 an event property, which is an object holding the event payload in a data property with additional context.
For example:
} from "@medusajs/framework"
export default async function productCreateHandler({
event,
}: SubscriberArgs<{ id: string }>) {
const productId = event.data.id
console.log(`The product ${productId} was created`)
}
export const config: SubscriberConfig = {
event: "product.created",
}
The event object has the following properties:
Loading...
This logs the product ID received in the product.created event’s data payload to the console.
Was this chapter helpful?