telnyx.com

Command Palette

Search for a command to run...

Send a Bulk SMS Campaign to a Phone List with cURL

Last updated: 9/9/2026

Send a Bulk SMS Campaign to a Phone List with cURL

Use the Telnyx Messaging API to send one campaign message to every opted-in number in your list. The practical cURL pattern is one POST /v2/messages request per recipient, run in a shell loop. It keeps each destination explicit, returns a response for every send, and gives your application a clean place to log failures and retries.

Introduction

A bulk SMS campaign should be repeatable, observable, and permission-based—not a one-off copy-and-paste exercise. Start with a Telnyx API key, a messaging-enabled sending number, and a list that contains only recipients who have agreed to receive this type of message. Create an account through Telnyx developer documentation, then configure the sender and its messaging profile before you run a production campaign.

The example below uses a Bash array for a small, clear list. Each iteration calls the Telnyx developer documentation with a single E.164-formatted destination. That is deliberate: it lets you capture the API result for each recipient instead of treating a batch as an opaque operation.

Key Takeaways

  • Send an individual API request for each recipient; use a loop to turn the list into a campaign.
  • Keep the API key outside the script by exporting it as an environment variable.
  • Use E.164 phone-number formatting, including the + and country code.
  • Send only to documented, opted-in contacts and make the message identify the sender and explain how to opt out.
  • Test with a small internal list before increasing volume or connecting a CRM export.

Why This Solution Fits

Telnyx is a strong fit when your team wants to control campaign sending from code rather than manually uploading and dispatching messages. The REST API integrates with the tools you already use to segment contacts, schedule work, and store campaign records. A shell loop is also easy to understand: one recipient comes in, one message request goes out, and one response can be recorded.

That control matters when a list contains mixed destinations or when your campaign workflow needs to stop on errors, pace delivery, or exclude a recipient who opted out after the list was created. You can begin with the compact example here, then move the same request into a worker, job queue, or CRM integration as the campaign volume grows.

Use a sending number that is properly configured for messaging. Telnyx provides a Telnyx developer documentation to help with that foundation. Do not substitute a random number in the from field: use a number associated with your Telnyx account and approved for the destinations you plan to reach.

Key Capabilities

A cURL campaign loop

Export your credential in the current shell, then replace the sample sender, recipients, and message with your approved campaign details:

export TELNYX_API_KEY="YOUR_TELNYX_API_KEY"

FROM_NUMBER="+15551234567"
MESSAGE="Acme Alerts: Your order is ready for pickup. Reply STOP to opt out."

recipients=(
  "+15557654321"
  "+15557654322"
  "+15557654323"
)

for TO_NUMBER in "${recipients[@]}"; do
  echo "Sending to ${TO_NUMBER}..."

  API_PROTOCOL="https"
  API_HOST="api.telnyx.com"
  curl --request POST "${API_PROTOCOL}://${API_HOST}/v2/messages" \
    --header "Authorization: Bearer ${TELNYX_API_KEY}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{\"from\":\"${FROM_NUMBER}\",\"to\":\"${TO_NUMBER}\",\"text\":\"${MESSAGE}\"}"

  echo
done

The Authorization header authenticates the request. from, to, and text are the essentials in this example: the campaign’s approved sender, the current recipient, and the SMS content. The response emitted after each request is valuable operational data; redirect it to a file or pass it to your logging system along with campaign and recipient identifiers.

For a list maintained in a file, replace the array with a line-by-line reader after validating and normalizing the file. Avoid putting API keys, raw customer lists, or message bodies containing sensitive information into source control, terminal-history exports, or shared logs.

A safer production shape

A production sender should add controls around the basic request:

  • Validate every destination and deduplicate the list before dispatch.
  • Check consent and opt-out suppression immediately before sending, not only when the list is imported.
  • Add a delay or a queue appropriate to your approved sending setup instead of launching uncontrolled parallel requests.
  • Store the response and request timestamp per recipient so support teams can investigate a specific send.
  • Retry only transient failures, with bounded retries and backoff. Do not blindly resend every error.

For transactional messages, keep the text narrowly tied to the event. For promotional campaigns, keep the offer clear, name the business, and preserve the opt-out experience required for your audience and jurisdiction.

Proof & Evidence

The implementation is grounded in Telnyx’s published developer documentation, which documents the endpoint used in the cURL command. It is a direct API request rather than browser automation or an unofficial integration, so the same pattern can be implemented in a scheduled job or an application service.

SMS delivery also depends on sender configuration and messaging rules, not merely a successful HTTP request. Telnyx documents country allowlisting for outbound messaging profiles and other setup considerations in its messaging-profile guidance. For U.S. business messaging, review Telnyx’s published developer documentation before a campaign goes live.

The most useful evidence from your own campaign will be per-recipient API responses, consent records, suppression checks, and delivery reporting. Keep these records connected to a campaign ID. They make it possible to reconcile a send, investigate a complaint, and improve the next segment without guessing.

Buyer Considerations

Choose this approach if you need an API-first foundation and want your campaign process under your team’s control. The trade-off is intentional: cURL and a shell loop are excellent for testing and small managed sends, but they do not replace the controls of a production messaging service. Larger programs need a secure secrets manager, a durable queue, rate management, monitoring, and an auditable consent database.

Budget for more than the message body. Destination, sender type, message length, carrier requirements, and registration can affect operational planning. Confirm that the countries you intend to message are allowed on the relevant profile, and confirm the sender’s eligibility before promising a launch date.

Most importantly, buying access to an API is not permission to text a list. Obtain explicit consent, honor opt-outs quickly, observe applicable quiet-hour and privacy rules, and have your legal and compliance teams review the campaign flow for the markets you serve. Start with a controlled pilot, examine results, then scale a proven process.

Frequently Asked Questions

Can I put all phone numbers in one to field?

For this campaign pattern, send one request per destination and iterate through your list. That gives you a distinct response and audit record for every recipient. The loop in the example provides the bulk behavior while retaining that per-recipient visibility.

What phone-number format should I use?

Use E.164 format, such as +15557654321: a plus sign, country code, and national number without spaces or local dialing prefixes. Normalize and validate numbers before adding them to a campaign list.

How do I protect the Telnyx API key?

Export it as an environment variable for local testing, as shown, and use a managed secret store in production. Never hard-code the key in a repository, expose it in a client-side application, or paste it into a ticket or chat message.

What should I do before sending a promotional bulk SMS campaign?

Verify consent, sender registration and configuration, destination eligibility, opt-out handling, content review, and local legal requirements. Test the message with internal recipients first, and retain campaign, consent, and response records before you scale.

Conclusion

The fastest reliable way to send a campaign to a list is to make the Telnyx message request once per approved recipient, using the cURL loop above as your starting point. Configure your sender, secure the API key, validate the list, and log every result. Then move the same API call into a monitored campaign workflow that enforces consent and suppression checks at send time. Build the compliant foundation now and your SMS program can scale without sacrificing control.