Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions main/docs/customize/events/create-an-event-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,88 @@ terraform apply -var="webhook_endpoint_url=https://<your-ngrok-url>/webhook"

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).

## Auth0 Actions

The information below describes how you can create and enable an event stream using Auth0 Actions.


### Create an event stream (Actions)

<Tabs><Tab title="Management API">

Event streams allow you to capture real-time changes within your Auth0 tenant and send them to an external system for processing.

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.

```bash wrap lines
auth0 events create \
--name "user-lifecycle-action" \
--type "action" \
--subscriptions "user.created" \
--configuration '{"status":"enabled","code":"exports.onExecuteEventStream = async (event, api) => { console.log(event.message.type); };"}'```
```


If successful, this call returns the following JSON with your event stream `id`. New event streams are enabled by default.

```json lines
{
"configuration": {
"action_id": "act_xyz789...",
"status": "enabled"
}
}
```


</Tab><Tab title="Dashboard">

To create an event stream in the Auth0 Dashboard using Auth0 Actions:
1. Navigate to **Auth0 Dashboard** > **Event Streams (Early)**.
2. Select **+Create Event Stream**. .
3. From the list of stream types, select **+Auth0 Actions**. This opens the configuration form for your new Auth0 Actions stream.
4. **Configure Stream Details:** In the configuration form, you need to provide the following information:

* **Stream Name:**

Enter a descriptive name for your event stream. This will help you identify it within the Auth0 Dashboard.

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`).
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.
```javascript
/**
* Handler that will be called during the execution of an Event Stream.
* @param {Event} event - Details about the Cloud Event.
* @param {EventStreamAPI} api - Interface whose methods can be used to handle the event.
*/
exports.onExecuteEventStream = async (event, api) => {
const eventType = event.message.type;
const eventData = event.message.data;

console.log(`Received event: ${eventType}`);

// Custom Logic: e.g., Send data to an external API
// await axios.post('https://my-crm.com/ingest', eventData);

// FAILURE HANDLING:
// To trigger a retry, either throw an error or use api.message.fail()
if (!eventData) {
// api.message.fail('No data received');
throw new Error('No data received');
}

// SUCCESS:
// If the function ends without error, the event is marked delivered.
};
```
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.

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.

</Tab>
</Tabs>


## Learn more

* [Event Types](/docs/customize/events/event-types)
Expand Down