App Router
Send a test request from Next.js.
Call SavaraFlow from server-side code when an order or account event is committed.
Connect your application
Set the server environment
Set SAVARA_HOST and SAVARA_TEST_KEY on the server. Keep both out of NEXT_PUBLIC_ variables and Client Components.
Call the helper from server code
Use an authenticated Route Handler, a protected Server Action, or a background job. Validate the application event and check user permissions before calling the helper.
Store the result
Log the status and message ID with your application event. Keep the same idempotency key when you retry that event.
export async function simulatePickup(orderId) {
const response = await fetch(
process.env.SAVARA_HOST + "/api/v1/messages",
{
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.SAVARA_TEST_KEY,
"Content-Type": "application/json",
"Idempotency-Key": "pickup-" + orderId,
},
body: JSON.stringify({
channel: "SMS",
to: "+256770123456",
body: "Your order is ready to collect.",
scenario: "delivered",
}),
signal: AbortSignal.timeout(10000),
}
);
return { status: response.status, result: await response.json() };
}Before sending live
Use your own SavaraFlow deployment origin without a trailing slash and a scoped key from that deployment. Switch to a live key only after enabling the route and funding the workspace. Remove the sandbox scenario, use a recipient who agreed to receive the message, and include consent: true in the request. Keep API keys in server-side configuration.
Get a quote before your first live send.
Use the live quote endpoint to review the destination cost and available balance.