API Integrations Masterclass · Chapter 2 · 10 min
Your first programmatic message
Send, observe and reason about delivery using the in-browser mx SDK.
Send something real-ish
Theory is cheap, but seeing a message fly through the system is invaluable for understanding the mechanics. The playground below runs your JavaScript inside a sandboxed Web Worker with a simulated SDK called mx. It behaves like the real ub3r provider where send resolves as soon as the message is accepted. The delivery receipt arrives roughly 800ms later on its own schedule to simulate real-world network latency.
Waiting for output…
Understanding Promises
The promise returned by mx.sms.send resolves with a message id and status sent immediately. It does not wait for delivery because the delivery process is inherently asynchronous and depends on external networks. If your code needs to know about delivery, it must subscribe to status events rather than awaiting the send call. This is the single most common misunderstanding in first-time API integrations.
Building a Robust Client
A good client library should handle more than just the raw HTTP request; it should manage authentication. When using the ub3r SDK, you can focus on your business logic while the library takes care of the low-level details. It is also a good practice to wrap these SDK calls in your own service layer for easier testing. This allows you to easily switch providers or add global logging without changing your entire codebase.
const result = await mx.sms.send({
to: "+15550109999",
text: "Hello from the ub3r platform!",
channel: "sms"
});
console.log("Message accepted with ID:", result.id);Input Validation Strategies
Normalise numbers to E.164 before they ever reach the API to avoid common formatting errors. Providers will reject poorly formatted numbers with a 422 Unprocessable Entity error immediately. Validation belongs at the edge of your system where the human user typed the input. This saves you from wasting resources on messages that are destined to fail from the very start of the process.
Monitoring Your Sends
Monitoring the success and failure rates of your initial sends is crucial for production stability. You should track how many messages result in a 202 Accepted versus terminal error codes like 400. This data helps you identify patterns in user input that might be causing delivery failures. Over time, these insights allow you to refine your validation logic and improve the overall reliability of your system.
Discussion (3)
Ran the playground with three concurrent sends — receipts came back out of order, exactly as the text says. Great way to make it stick.
Good point — we're adding a short section on this in the next revision.
We learnt the idempotency lesson the expensive way: duplicate OTPs during an incident. This chapter is now required reading on my team.