Twilio REST API Guide

Use Twilio Messaging to send SMS and MMS and track delivery, Lookup to validate and format a phone number, and Verify to confirm that a user can receive a code at that number. All ten examples make direct HTTPS requests with Chilkat.Http and work without a webhook.

For live requests, enable Http.BasicAuth and set Login to the API key SID and Password to its secret. Load the credentials from private application configuration. The Account SID in a Messaging URL identifies the account whose messages you are working with. Use HttpNoBody for a GET. For a POST, add the form fields with HttpRequest.AddParam, set the content type to application/x-www-form-urlencoded, and submit with HttpReq. Pass the phone number with its leading plus sign so Chilkat can encode it correctly.

Messaging

Send a message and track delivery

Start with the SMS example to try the request using Twilio’s test Account SID, test Auth Token, and test sender number. Twilio simulates this send. For an actual delivery, use live credentials and a sender enabled for the channel. For MMS, also supply a MediaUrl that Twilio can fetch and that serves the file with the correct content type. Twilio test credentials.

HTTP 201 means Twilio created the message. Save the Message SID from a live send and use it to fetch the current status. queued means it is waiting to be sent, sent means an upstream carrier accepted it, and delivered means Twilio received delivery confirmation. For failed or undelivered, inspect the available delivery error details. Twilio Messages reference.

Download media from an MMS

Start with the Message SID and list its media records. The .json representation describes an item. Request the individual media resource without that extension to get its bytes. If Twilio returns a temporary download URL, the example follows it with a separate HTTP client so the API credentials stay with Twilio. Twilio Media reference.

Schedule or cancel a send

Scheduling is a live operation. Supply a Messaging Service SID, ScheduleType=fixed, and a SendAt timestamp in UTC. Choose a time between 15 minutes and 35 days ahead. Save the returned Message SID. To cancel before the send, use that SID on a later run and check that the returned status is canceled. Twilio scheduling guide.

Read message history

List the account’s messages to see inbound and outbound activity. Use the date-filtered example when you know the sending period. Both bounds are inclusive GMT calendar dates. PageSize controls the size of one response. Follow Twilio’s next_page_uri until it is null to read the full result.

Phone number lookup

When a user enters a number in national format, supply its two-letter country code to Lookup v2. Read the valid flag even when the HTTP request succeeds. For a valid number, phone_number gives the E.164 form to pass to Messaging or Verify, and national_format gives the local display form. For an invalid number, inspect validation_errors when present. Twilio Lookup reference.

Phone verification

Use Verify when the application needs the user to demonstrate access to a phone. Create a Verify Service once and use its Service SID (VA…) in both requests.

  1. Send the code. When the user requests verification, post the phone number and Channel=sms to Verifications. This sends a live SMS. When the status is pending, save the returned Verification SID (VE…) with the user and phone number, then prompt for the code.
  2. Check the code. Retrieve the saved Verification SID for that user. Pass it and the entered code to VerificationCheck. Keep the code as text to preserve leading zeros. Record success only when Twilio returns approved. An expired or already completed verification can return HTTP 404. Twilio Verification Check reference.