How to Trigger a Flow with Custom Events
Shows how to trigger a Recart flow for an existing subscriber from your backend using custom events.
This guide walks you through triggering a Recart flow from your own backend using custom events. The flow involves creating an event source with a "custom" type, setting up an integration flow, and then posting events that trigger it.
Use this when something happens in your system that should start an SMS flow for an existing subscriber — a failed payment, a back-in-stock item, a shipped order, a completed booking.
Custom events do not collect consent. A custom event only triggers messaging for a phone number that is already an opted-in SMS subscriber. If you need to subscribe someone as part of the same integration, use an event source with the
optintype instead — see How to Setup a Subscription Flow.
Overview
The custom event flow consists of three main steps:
Create an Event Source - Register a new event source with "custom" type
Create an Integration Flow - Create a new integration flow with the event source in Recart application
Post Events - Send events referencing that event source to trigger the flow
Step 1: Create an Event Source with Custom Type
An event source declares the kind of event you will be sending, so it can be selected as a flow trigger in the dashboard. It only needs to be created once per event type.
Prerequisites
Valid API credentials for the Recart API
Access to the event source creation endpoint
Process
Prepare Event Source: Specify the event source type as "custom", along with the
categoryandnamethat identify your event.Example payload:
Note the two different
typefields: the outerdata.typeis the JSON:API resource type and must always be the literalevents, even when creating an event source. The innerattributes.typeis what selectscustomoroptin.The
categoryandnamepair is what you will select in the dashboard, and what every event must repeat verbatim:category— the integration or system the event comes from (e.g.payment,inventory,booking)name— the event itself (e.g.billing attempt failed,back in stock)
Make API Request: Send a request to create the event source through the appropriate endpoint in the Recart API.
Create a separate event source for each distinct event you want to trigger a flow, so each one can drive its own flow.
Step 2: Create an Integration Flow
An active integration flow must exist for the event source, otherwise posted events have nothing to trigger.
Prerequisites
Successfully created event source from Step 1
Access to Recart dashboard
Process
Navigate to SMS Integrations: Open the Recart dashboard and navigate to Automated flows > SMS Integrations.
Create a New Flow: Create a new Integration flow.
Configure the Trigger: Select the trigger and set the integration and event pair to the event source created in Step 1 — the integration is the source's
category, the event is itsname.Compose the Messages: Build the messages the flow should send when the event arrives.
Save and Activate the Flow: Click "Activate" in the upper right corner to enable the flow.
Step 3: Post Events
With the event source registered and the flow activated, post an event whenever the corresponding thing happens in your system.
Prerequisites
Successfully created event source from Step 1
Active integration flow from Step 2
The subscriber's phone number
Process
Detect the Event: Trigger this step from whatever happens in your system — a webhook from your payment provider, a job that detects restocked inventory, a state change in your own database.
Reference the Event Source: Set
source.categoryandsource.nameto exactly the values used in Step 1. A mismatch is rejected with417— the pair must match a registered event source.Attach Event Data (optional): Pass event data in
properties.Properties are not automatically available to the flow. Only properties that Recart already supports are delivered to messages, where the message inserts one from the flow editor's variable picker. Contact Support to find out which properties your account can use, or to request support for a new one.
Any other property is accepted and then discarded. The request still returns
200and the flow still triggers, so a discarded property looks exactly like a delivered one — there is no warning. Do not design a message around a property you have not confirmed is supported. To personalise or target on your own data, store it on the subscriber withPATCH /subscribersand use it as a segment condition instead.Example payload:
Submit the Event: Send the request to the
POST /eventsendpoint in the Recart API reference.Handle Response: A
200means the event was accepted and queued — not that a message was sent. Error responses carry anerrorsarray whosecodeanddetailidentify the cause:StatusCodeWhat it means400ERR_BAD_REQUESTPayload failed validation, or
phoneNumberis unparseable.detaillists the offending fields.401ERR_UNAUTHORIZEDThe
X-Recart-API-Keyheader is missing.403ERR_FORBIDDENThe API key is unknown or has been revoked.
404ERR_NOT_FOUNDNo subscriber exists for
phoneNumber.415ERR_UNSUPPORTED_MEDIA_TYPEContent-Typemust beapplication/vnd.api+jsonorapplication/json.417ERR_EXPECTATION_FAILEDEither the event source is not registered for the site, or the subscriber has no active SMS subscription.
detaildistinguishes the two.500ERR_INTERNAL_SERVER_ERRORThe subscriber could not be looked up, or the event could not be queued. The event was not processed, so it is safe to retry.
400,404,415and417are permanent for the given payload — retrying unchanged will fail the same way. Retry only5XXand network failures, so an event is not silently lost.Two cases fall outside this envelope and return an unstructured plain-text body instead of an
errorsarray: aContent-Typethe API cannot parse at all, and a malformed JSON body (400). Check the status code before parsing the body as JSON.
Important Considerations
Event Properties
Maximum 10 properties per event — an eleventh is rejected with
400Keep values flat strings or numbers. Nested objects, arrays and booleans are accepted by validation rather than rejected, but they are ignored like any unsupported property
Triggering Requirements
The event source
categoryandnamemust match the values in the event exactly — a mismatch is reported as417, not as a silent failureA newly registered event source does not become usable instantly. Allow a short delay before posting the first event against it, and expect the first events to be able to fail with
417until it has propagatedThe integration flow must be active. Flow state is not validated when the event is posted: if no active flow uses the event source as its trigger, the event is still accepted with
200and simply results in no message. When events succeed but nothing is sent, check the flow firstThe phone number must belong to an existing SMS subscriber; custom events do not create subscriptions
Phone numbers should be in E.164 format (e.g., +1234567890)
Messaging Requirements
Comply with TCPA regulations and local SMS marketing laws
Only send transactional or promotional content consistent with the consent the subscriber gave
Post events as the underlying thing happens — flows are triggered in real time, so stale events reach subscribers as if they were current
Last updated
Was this helpful?