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.
The Stream Hub is in beta, and it's available only to our enterprise customers, meaning that only the changes to resources belonging to enterprise organizations are pushed to the event stream. At the moment, there's no time limits on the event history storage. We will use this beta period before the official release to run load tests and determine how long to retain past event information.
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.
If, for any reason, the connection to the stream hub drops before being intentionally closed, ensure that your stream reader app handles a reconnection/retry policy. Keep in mind that the disconnected stream is considered stale after 5 secs, so you cannot request a new real-time stream until 5 secs after the connection drop.
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.
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).
In the near future, more information will be added to the stream (e.g. external payloads so as to be able to track events like: webhooks received from payment gateways, API calls made to third-party services, other side-effects tied to a specific resource, etc.).
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.
Any call to the stream endpoints must be authenticated using integration API credentials.
Once connected, each message in the stream follows a simple format:
event
The type of 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).
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 timeframe cannot exceed 7 days.
The /replay
endpoint accepts the desired timeframe, resource type, and optional resource IDs as query parameters:
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:
replay_started
A replay stream has started.
stream_complete
A replay stream has been completed.
While the real-time stream notifies about all the events related to the organization regardless of the environment, the replay stream shows only the events related to the environment (test or live) associated with the integration token used to authenticate the API call.
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:
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