Event stream hub

Unified SSE-based stream of the Core API resource lifecycle events, with support for time-based and resource-based replay

In addition to a webhook-based event handling, Commerce Layer also provides a Change Data Capture (CDC) system to capture and track changes to data instantly.

Leveraging Server-Sent Events (SSE), we enable clients to receive real-time notifications for any changes to the resources exposed by our platform (e.g. SKUs, orders, customers, etc.) just by subscribing to an event stream and consume updates as they happen.

SSE provides a lightweight, one-way communication channel from the server to the client over a single long-lived HTTP connection. It’s ideal for real-time feeds, system monitoring, or keeping local caches in sync with backend state. The protocol uses standard HTTP and the text/event-stream content type to send a stream of UTF-8 encoded messages from the server to the client. Once connected, the client listens for incoming messages without needing to poll until the connection is closed.

Once reconnected, any event message that you hadn't received yet but the consumers had already started to process in the last 30 mins is re-pushed to the live stream. Previous messages (dating back over half an hour from the disconnection) can always be recovered by passing a specific time frame to the /replay endpoint of the stream hub.

Supported events

Currently, the list of events pushed to the Commerce Layer Stream Hub includes all the create, update, and delete operations on any Core API resource.

Event type
Description

heartbeat

Checks the connection to the stream every 10 secs.

create

A new resource has been created.

update

An existing resource has been updated.

destroy

An existing resource has been destroyed.

anonymization_request

The anonymization of a customer's data has been requested (available for the customer resource only).

anonymization_cancel

An ongoing customer's data anonymization request has been revoked (available for the customer resource only).

Connecting to the event stream

To start a connection to the Commerce Layer Stream Hub, you just need to send a GET request to the following endpoint:

https://stream.commercelayer.io/{{your_domain}}

Where {{your_domain}} is the unique subdomain of your Commerce Layer organization.

This endpoint automatically acknowledges messages as they are streamed to the client.

Once connected, each message in the stream follows a simple format:

Key
Description

event

id

A unique identifier for the event.

data

A JSON object representing the resource and highlighting the delta of the change (or just a timestamp in case of heartbeats).

The data object of each event message (other than the heartbeats) basically contains the whole related event store resource object, providing information about the type of change, the affected resource, the object changes payload, the actor who triggered the change, the exact timestamp of the change, and more (see the response in the example below).

Example

The following request starts a connection to the event stream of the enterprise organization with slug my-org:

curl -g -X GET \
  'https://stream.commercelayer.io/my-org' \
  -H 'Authorization: Bearer your-access-token' 

Event recovery and replay by resource

Along with the live stream, the Commerce Layer Stream Hub service offers an additional endpoint that queues a replay job to retrieve historical events:

https://stream.commercelayer.io/{{your_domain}}/replay

This is useful for clients that were disconnected, are syncing a local store, or need to audit events over a given timeframe. The same endpoint can also be used to fetch the events related to a specific resource or to a set of specific instances of that resource.

The /replay endpoint accepts the desired timeframe, resource type, and optional resource IDs as query parameters:

Query parameter
Required
Description
Example

date_from

The ISO8601 timestamp for the start of the replay window (YYYY-MM-DDTHH:MM:SSZ) — must be no more than 7 days before date_to, optional if you're passing resource_id_in.

2025-01-10T12:15:00Z

date_to

The ISO8601 timestamp for the start of the replay window (YYYY-MM-DDTHH:MM:SSZ) — must be no more than 7 days after date_from, optional if you're passing resource_id_in.

2025-01-16T12:15:00Z

resource_type_eq

The type of resource for which you need to replay the event changes — required if you're passing resource_id_in.

skus

resource_id_in

A comma-separated list of IDs of the specified resource type (no space after the comma).

AYqPSwAqDW,WRfaDFdGeOK

The /replay endpoint also introduces two additional types of events to notify of the beginning and the completion of the replay stream:

Event type
Description

replay_started

A replay stream has started.

stream_complete

A replay stream has been completed.

Of course, being a replay, no heartbeat will show in the stream in this case.

Examples

Replay by timeframe

The following request replays the events streamed within a specified time window:

curl -g -X GET \
  'https://stream.commercelayer.io/my-org/replay?date_from=2025-07-30T16:00:00Z&date_to=2025-07-31T16:30:00Z' \
  -H 'Authorization: Bearer your-access-token' 

Replay by resource type

The following request replays only the events related to SKUs, streamed within a specified time window:

curl -g -X GET \
  'https://stream.commercelayer.io/my-org/replay?date_from=2025-07-30T15:15:00Z&date_to=2025-07-31T16:30:00Z&resource_type_eq=skus' \
  -H 'Authorization: Bearer your-access-token' 

Replay by resource IDs

The following request replays only the events related to the SKUs identified by the IDs nQrOSKprmZ and WJoqSjzGjB with no time window restriction:

curl -g -X GET \
  'https://stream.commercelayer.io/my-org/replay?resource_type_eq=skus&resource_id_in=nQrOSKprmZ,WJoqSjzGjB' \
  -H 'Authorization: Bearer your-access-token' 

Response codes

The Commerce Layer Stream Hub uses HTTP response codes to show the success or failure of a request to connect to the event stream.

Success

In case of successful connection, the API responds with a 200 OK status code and starts streaming data according to the SSE format.

Error

In case of error, a descriptive error message is returned along with the related error code:

Code
Description

400

Bad request

The date format is invalid or the date range validation failed.

401

Unauthorized

The JWT token is invalid (expired, not associated with integration API credentials, etc.) or missing.

403

Forbidden

An organization slug mismatch or validation error occurred.

409

Conflict

An active consumer already exists (you can kill the stream and retry in 5 secs).

500

Internal server error

Something went wrong and the stream hub failed to queue the replay job.

Last updated