* docs improvements and changes * updated module definition * modules + dml changes * fix build * fix vale error * fix lint errors * fixes to stripe docs * fix condition * fix condition * fix module defintion * fix checkout * disable UI action * change oas preview action * flatten provider module options * fix lint errors * add module link docs * pr comments fixes * fix vale error * change node engine version * links -> linkable * add note about database name * small fixes * link fixes * fix response code in api reference * added migrations step
47 lines
1.4 KiB
Plaintext
47 lines
1.4 KiB
Plaintext
export const metadata = {
|
||
title: `${pageNumber} Event Data Payload`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
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 the event's data payload.
|
||
|
||
For example:
|
||
|
||
export const highlights = [
|
||
["7", "", "The event's data payload."],
|
||
["8", "{ id: string }", "The type of expected data payloads."],
|
||
["9", '"data" in data ? data.data.id : data.id', "The payload data is either in `data.data` or directly in `data`."]
|
||
]
|
||
|
||
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-5" expandButtonLabel="Show Imports"
|
||
import type {
|
||
SubscriberArgs,
|
||
SubscriberConfig,
|
||
} from "@medusajs/medusa"
|
||
|
||
export default async function productCreateHandler({
|
||
data,
|
||
}: SubscriberArgs<{ id: string }>) {
|
||
const productId = "data" in data ? data.data.id : data.id
|
||
console.log(`The product ${productId} was created`)
|
||
}
|
||
|
||
export const config: SubscriberConfig = {
|
||
event: "product.created",
|
||
}
|
||
```
|
||
|
||
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](!resources!/events-reference) for a full list of events emitted by Medusa and their data payloads. |