Skip to content

Commit bff0499

Browse files
Update create-an-event-stream.mdx (#385)
* Update create-an-event-stream.mdx * Update create-an-event-stream.mdx * Update create-an-event-stream.mdx * Update create-an-event-stream.mdx * Update create-an-event-stream.mdx
1 parent c49b8eb commit bff0499

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

main/docs/customize/events/create-an-event-stream.mdx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,88 @@ terraform apply -var="webhook_endpoint_url=https://<your-ngrok-url>/webhook"
586586

587587
After the stream is active, you can test the event stream. For more information, review [**Event Testing, Observability, and Failure Recovery**](/docs/customize/events/event-testing-observability-and-failure-recovery).
588588

589+
## Auth0 Actions
590+
591+
The information below describes how you can create and enable an event stream using Auth0 Actions.
592+
593+
594+
### Create an event stream (Actions)
595+
596+
<Tabs><Tab title="Management API">
597+
598+
Event streams allow you to capture real-time changes within your Auth0 tenant and send them to an external system for processing.
599+
600+
Before setting up an event stream, you need to identify the [event types](/docs/customize/events/event-types) you want to monitor. This example uses the Auth0 CLI to create an event stream that subscribes to the `user.created` event, which triggers whenever your tenant registers a new user.
601+
602+
```bash wrap lines
603+
auth0 events create \
604+
--name "user-lifecycle-action" \
605+
--type "action" \
606+
--subscriptions "user.created" \
607+
--configuration '{"status":"enabled","code":"exports.onExecuteEventStream = async (event, api) => { console.log(event.message.type); };"}'```
608+
```
609+
610+
611+
If successful, this call returns the following JSON with your event stream `id`. New event streams are enabled by default.
612+
613+
```json lines
614+
{
615+
"configuration": {
616+
"action_id": "act_xyz789...",
617+
"status": "enabled"
618+
}
619+
}
620+
```
621+
622+
623+
</Tab><Tab title="Dashboard">
624+
625+
To create an event stream in the Auth0 Dashboard using Auth0 Actions:
626+
1. Navigate to **Auth0 Dashboard** > **Event Streams (Early)**.
627+
2. Select **+Create Event Stream**. .
628+
3. From the list of stream types, select **+Auth0 Actions**. This opens the configuration form for your new Auth0 Actions stream.
629+
4. **Configure Stream Details:** In the configuration form, you need to provide the following information:
630+
631+
* **Stream Name:**
632+
633+
Enter a descriptive name for your event stream. This will help you identify it within the Auth0 Dashboard.
634+
635+
5. **Select Event Types:** In the **Select Event Types** section, choose the specific Auth0 event types you want to include in this stream. You can select multiple event types based on your requirements (e.g., `Created`, `Updated`, `Deleted`).
636+
6. In the **Action Editor**, write your handler code. The system requires the `onExecuteEventStream` function. You can use the `api` object to manage success or failure states.
637+
```javascript
638+
/**
639+
* Handler that will be called during the execution of an Event Stream.
640+
* @param {Event} event - Details about the Cloud Event.
641+
* @param {EventStreamAPI} api - Interface whose methods can be used to handle the event.
642+
*/
643+
exports.onExecuteEventStream = async (event, api) => {
644+
const eventType = event.message.type;
645+
const eventData = event.message.data;
646+
647+
console.log(`Received event: ${eventType}`);
648+
649+
// Custom Logic: e.g., Send data to an external API
650+
// await axios.post('https://my-crm.com/ingest', eventData);
651+
652+
// FAILURE HANDLING:
653+
// To trigger a retry, either throw an error or use api.message.fail()
654+
if (!eventData) {
655+
// api.message.fail('No data received');
656+
throw new Error('No data received');
657+
}
658+
659+
// SUCCESS:
660+
// If the function ends without error, the event is marked delivered.
661+
};
662+
```
663+
7. **Save Changes:** Once you have configured the stream name and Action handler, the system automatically creates the Action, bind it to a stream, and enables it.
664+
665+
Your new event stream is now created, and Auth0 can begin publishing the selected event types to the specified Auth0 Action. You can monitor the status and manage your event stream from the Event Streams (Early) page in the Auth0 Dashboard.
666+
667+
</Tab>
668+
</Tabs>
669+
670+
589671
## Learn more
590672
591673
* [Event Types](/docs/customize/events/event-types)

0 commit comments

Comments
 (0)