To send an SMS from Node-RED, use a function node to build the JSON body and headers, a delay node set to rate limit, and an http request node that POSTs to the SMS API. Then check msg.statusCode in a second function node, because the http request node doesn't raise an error on a 4xx or 5xx answer, and use a catch node for the failures it does throw, such as a timeout.
We make Ready, so the flow uses our REST API and only the request shape we document: POST /v1/messages with to, body and consent_attested, plus X-API-Key and Idempotency-Key.
The flow
- Trigger: an inject, MQTT in or http in node supplies
msg.toandmsg.text. - function (build): sets the URL, headers, body and a key.
- delay (rate limit): one message per second.
- http request: POSTs to the API.
- function (verdict): three outputs for done, retry and park.
- Retry output: a delay node (back off), then back to step 2.
- Park output: an alert, email or log a person reads.
- catch: scoped to the http request node, wired into the verdict function.
| Node | Key setting |
|---|---|
| function (build) | One output, sets msg.headers and msg.payload |
| delay | Action: Rate Limit, 1 msg per 1 second, don't drop intermediate messages |
| http request | Method: set by msg, or POST; Return: a parsed JSON object |
| function (verdict) | Outputs: 3 |
| delay (back off) | Action: Delay each message, "Override delay with msg.delay" |
| catch | Scope: the http request node only |
The build function
Put the API key in an environment variable on the machine that runs Node-RED (READY_API_KEY), not in the flow, since flow files get exported and shared. A function node reads it with env.get().
// function node: build
const key = msg.key || crypto.randomUUID();
msg.key = key;
msg.attempt = msg.attempt || 0;
msg.method = 'POST';
msg.url = 'https://api.tryready.com/v1/messages';
msg.headers = {
'Content-Type': 'application/json',
'X-API-Key': env.get('READY_API_KEY'),
'Idempotency-Key': key,
};
msg.payload = {
to: msg.to,
body: msg.text,
consent_attested: true,
};
return msg; Two details. In recent Node-RED versions the crypto module is available to a function node, but in older ones you may need to add it under Setup, then Modules (and allow it in functionExternalModules in settings). Second, the key is created once and stored on msg.key. When a message loops back for a retry, the build step doesn't run again, so the same key goes out every time. A repeated key means the request isn't sent twice.
Set consent_attested to true only when the recipient agreed to texts. msg.to must be E.164, such as +12125550199. See our E.164 guide for cleaning numbers.
Rate limit and http request
Add a delay node and choose Rate Limit, then set it to allow 1 message per 1 second. Leave Drop intermediate messages off. If you turn it on, the node discards everything except the newest message while it waits, which means texts silently disappear. Our rate limits guide explains how to pick a rate.
The http request node needs very little set up, since the function node already filled in msg.url, msg.method and msg.headers. Leave the URL field blank, pick Return: a parsed JSON object, and set a request timeout in the node if your version offers one. Because msg.payload is an object, Node-RED sends it as JSON.
The verdict function
The http request node puts the status code on msg.statusCode and the response on msg.payload. A 429 or a 500 arrives as a normal message, not an error. This function node has three outputs:
// function node: verdict (3 outputs: done, retry, park)
const status = msg.statusCode;
const text = typeof msg.payload === 'string' ? msg.payload : JSON.stringify(msg.payload);
if (status >= 200 && status < 300) return [msg, null, null];
const retryable =
status === 429 || status === 500 ||
(status === 409 && text.includes('idempotency_in_progress'));
if (status === 409 && text.includes('QUIET_HOURS_BLOCK')) {
msg.delay = 60 * 60 * 1000; // a time rule: wait, then send again
return [null, msg, null];
}
if (status === 503) {
msg.key = null; // not sent, so a new key is safe
msg.attempt += 1;
msg.delay = 2 ** msg.attempt * 1000;
return msg.attempt > 5 ? [null, null, msg] : [null, msg, null];
}
if (retryable || status === undefined) {
msg.attempt += 1;
msg.delay = 2 ** msg.attempt * 1000;
return msg.attempt > 5 ? [null, null, msg] : [null, msg, null];
}
return [null, null, msg]; // other 4xx: a person has to look Output 2 goes to a delay node set to Delay each message with Override delay with msg.delay ticked, then back into the build function, which keeps msg.key when it's set and makes a new one only when it's empty. That's why a 503 clears the key and every other retry keeps it.
Output 3, the parked messages, should end somewhere a person looks: an email, a file, a Slack message, a database row. A bad number or an opted-out contact will fail every time, so retrying it only wastes calls. The full list of statuses is in our retry guide and the error codes docs. For the quiet hours rule, see handling the 409.
The catch node
When the http request node does throw (a timeout, a refused connection, DNS trouble), no statusCode exists. Add a catch node, set its scope to that node only, and wire it into the verdict function. The check status === undefined above then treats it as a retry, with the same key, which is safe.
A catch node on its own would also swallow errors from other nodes if left on the default scope, so pick the http request node by name.
When Node-RED is the wrong place for the queue
Node-RED keeps messages in memory. A restart loses every message that's waiting in the rate limit node or in a back-off delay. For a hobby project or a sensor alert, that's acceptable. For texts that must arrive, store the job first, for example in a database or a queue, and let the flow read from it. Our RabbitMQ consumer guide shows one pattern, and the n8n guide covers a similar visual tool.
FAQ
Can a function node call the API directly, without an http request node?
Yes, with fetch if your runtime has it, but you then rebuild the timeout and error handling that the node provides. The http request node keeps the flow readable.
How do I stop an alert from texting someone every second?
Add a delay node set to rate limit with a longer interval, or keep a timestamp in flow context and skip a send inside a cool-down window. Without that, a noisy sensor can send the same text repeatedly.
Where do I put the API key for a Docker install?
Pass READY_API_KEY as an environment variable on the container and read it with env.get(). Don't type it into a node.
The short version
One function node builds the request, a rate limit node protects the account, one verdict node decides what happens next, and a catch node covers network errors. The messages API docs list every field, and you can sign up to get a key.