Events & Workflows
Sending events
Send an event when an action succeeds in your application, such as creating an account or confirming a booking.
Send your first event
Continuing the order example, send order.created to POST /api/v1/events with your project API key. Put your order JSON inside data.
| Field | What to send |
|---|---|
name |
The registered event name. |
object.type |
The type you registered, such as order. |
object.id |
Your record’s ID as a string. |
data |
The event’s values, including recipient details. |
Use the same object type and ID for related events. For example, order.created and order.shipped should identify the same order.
curl --request POST 'https://sendery.co/api/v1/events' \
--header "Authorization: Bearer $SENDERY_API_KEY" \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: order-created-1042' \
--data '{
"name": "order.created",
"object": { "type": "order", "id": "1042" },
"data": {
"id": "1042",
"buyer": {"name": "Alex", "email": "[email protected]"},
"seller": {"name": "Sam", "email": "[email protected]"},
"price": 49
}
}'$receipt = $sendery->event(
name: 'order.created',
objectType: 'order',
objectId: '1042',
data: [
'id' => '1042',
'buyer' => ['name' => 'Alex', 'email' => '[email protected]'],
'seller' => ['name' => 'Sam', 'email' => '[email protected]'],
'price' => 49,
],
)->retry()->send();$receipt = app(\Sendery\Laravel\Client::class)->event(
name: 'order.created',
objectType: 'order',
objectId: '1042',
data: [
'id' => '1042',
'buyer' => ['name' => 'Alex', 'email' => '[email protected]'],
'seller' => ['name' => 'Sam', 'email' => '[email protected]'],
'price' => 49,
],
)->retry()->send();$receipt = $sendery->event(
name: 'order.created',
objectType: 'order',
objectId: '1042',
data: [
'id' => '1042',
'buyer' => ['name' => 'Alex', 'email' => '[email protected]'],
'seller' => ['name' => 'Sam', 'email' => '[email protected]'],
'price' => 49,
],
)->retry()->send();const receipt = await sendery.event({
name: "order.created",
object: {type: "order", id: "1042"},
data: {
id: "1042",
buyer: {name: "Alex", email: "[email protected]"},
seller: {name: "Sam", email: "[email protected]"},
price: 49,
},
}).retry().send();receipt, err := client.SendEvent(ctx, sendery.EventInput{
Name: "order.created",
Object: sendery.EventObject{Type: "order", ID: "1042"},
Data: map[string]any{
"id": "1042",
"buyer": map[string]any{"name": "Alex", "email": "[email protected]"},
"seller": map[string]any{"name": "Sam", "email": "[email protected]"},
"price": 49,
},
}, sendery.WithRetries(3))
if err != nil {
return err
}const receipt = await sendery.event({
name: "order.created",
object: {type: "order", id: "1042"},
data: {
id: "1042",
buyer: {name: "Alex", email: "[email protected]"},
seller: {name: "Sam", email: "[email protected]"},
price: 49,
},
}).retry().send();const receipt = await sendery.event({
name: "order.created",
object: {type: "order", id: "1042"},
data: {
id: "1042",
buyer: {name: "Alex", email: "[email protected]"},
seller: {name: "Sam", email: "[email protected]"},
price: 49,
},
}).retry().send();receipt = sendery.event(
name="order.created",
object_type="order",
object_id="1042",
data={
"id": "1042",
"buyer": {"name": "Alex", "email": "[email protected]"},
"seller": {"name": "Sam", "email": "[email protected]"},
"price": 49,
},
).retry().send()from sendery_django import event
receipt = event(
name="order.created",
object_type="order",
object_id="1042",
data={
"id": "1042",
"buyer": {"name": "Alex", "email": "[email protected]"},
"seller": {"name": "Sam", "email": "[email protected]"},
"price": 49,
},
).retry().send()var receipt = sendery.event(
"order.created", "order", "1042",
Map.of(
"id", "1042",
"buyer", Map.of("name", "Alex", "email", "[email protected]"),
"seller", Map.of("name", "Sam", "email", "[email protected]"),
"price", 49
)
).retry().send();val receipt = sendery.event(
"order.created", "order", "1042",
mapOf(
"id" to "1042",
"buyer" to mapOf("name" to "Alex", "email" to "[email protected]"),
"seller" to mapOf("name" to "Sam", "email" to "[email protected]"),
"price" to 49
)
).retry().send()var receipt = sendery.event(
"order.created", "order", "1042",
Map.of(
"id", "1042",
"buyer", Map.of("name", "Alex", "email", "[email protected]"),
"seller", Map.of("name", "Sam", "email", "[email protected]"),
"price", 49
)
).retry().send();Include each recipient’s language
After adding language mappings, include the language codes in your event data. Here the buyer receives Japanese (ja) and the seller English (en). Each language must have a published translation in the template. Omit the language value to use the template’s default.
{
"name": "order.created",
"object": {"type": "order", "id": "1042"},
"data": {
"id": "1042",
"buyer": {"name": "Alex", "email": "[email protected]", "locale": "ja"},
"seller": {"name": "Sam", "email": "[email protected]", "locale": "en"},
"price": 49
}
}Check the response
202 confirms Sendery accepted the event. matched_workflows shows how many flows started; it is 0 if no active workflow matched. Use GET /api/v1/events/{id} to check its progress.
{
"id": "019b0123-1000-7000-8000-000000000001",
"status": "accepted",
"matched_workflows": 1
}Retries and data
Use the same Idempotency-Key when retrying a request to avoid starting the same flow twice. SDKs generate a key for you and reuse it with .retry(). See your SDK guide for an example.
Delayed emails use the data from the original event. Send only the information your emails need; it may be retained while a flow is waiting.