Request patterns and code samples
Copy-paste ready examples for common Ventryx API operations in multiple languages and environments.
List workflows
curl
curl https://api.ventryx.io/v1/workflows \ -H "Authorization: Bearer $VENTRYX_API_KEY"
Node.js (fetch)
const response = await fetch('https://api.ventryx.io/v1/workflows', {
headers: {
'Authorization': `Bearer ${process.env.VENTRYX_API_KEY}`,
},
});
const { data } = await response.json();
console.log(data);
Python (httpx)
import httpx
import os
client = httpx.Client(
base_url="https://api.ventryx.io/v1",
headers={"Authorization": f"Bearer {os.environ['VENTRYX_API_KEY']}"},
)
response = client.get("/workflows")
print(response.json()["data"])
Create a workflow
curl
curl -X POST https://api.ventryx.io/v1/workflows \
-H "Authorization: Bearer $VENTRYX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "User onboarding",
"trigger": { "event": "user.registered" },
"steps": [
{ "type": "send_notification", "channel": "email", "template": "welcome" }
]
}'
Node.js (fetch)
const response = await fetch('https://api.ventryx.io/v1/workflows', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.VENTRYX_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'User onboarding',
trigger: { event: 'user.registered' },
steps: [
{ type: 'send_notification', channel: 'email', template: 'welcome' }
],
}),
});
const { data } = await response.json();
console.log('Created workflow:', data.id);
Emit an event
curl
curl -X POST https://api.ventryx.io/v1/events \
-H "Authorization: Bearer $VENTRYX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "user.registered",
"data": {
"user_id": "usr_12345",
"email": "[email protected]",
"plan": "pro"
}
}'
Python
response = client.post("/events", json={
"type": "user.registered",
"data": {
"user_id": "usr_12345",
"email": "[email protected]",
"plan": "pro",
},
})
print(response.json()["data"]["id"])
Pagination
List endpoints support page and per_page query parameters. Default page size is 20, maximum is 100.
curl
curl "https://api.ventryx.io/v1/workflows?page=2&per_page=50" \ -H "Authorization: Bearer $VENTRYX_API_KEY"
The response meta object tells you the total count and current position:
{
"data": [...],
"meta": {
"total": 143,
"page": 2,
"per_page": 50
}
}
Error handling
Always check the HTTP status code. On errors, parse the error object for the machine-readable code:
Node.js
const response = await fetch('https://api.ventryx.io/v1/workflows', {
headers: { 'Authorization': `Bearer ${process.env.VENTRYX_API_KEY}` },
});
if (!response.ok) {
const { error } = await response.json();
console.error(`API error [${error.code}]: ${error.message}`);
// Handle specific codes:
if (error.code === 'rate_limit_exceeded') {
// back off and retry
}
} else {
const { data } = await response.json();
// use data
}