Tutorials
Send your first SMS message using Infobip API
Send your first SMS message using Infobip API

Send your first SMS message using Infobip API

Short Message Service (SMS) is widely used for different purposes, including marketing, customer support, and authentication. It remains the most reliable way to reach customers and guarantee message delivery.

SMS is compatible with all mobile devices and works without requiring an internet connection. It also boasts high open rates for campaigns and can help reduce messaging costs.

In this tutorial, you will learn how to send an SMS message using the Infobip SMS API.

We will use the 3 SMS API version which has a unified look and feel like other Infobip channel APIs.

Prerequisites

  1. Infobip account (opens in a new tab). If you do not have one, you can create a free trial account (opens in a new tab).
  2. Infobip API key with sms:message:send scope. You can find out more about how to create an API key with the correct scope here (opens in a new tab).
  3. Your favorite HTTP client. In this example, we will use curl. Additionally, you can choose the official Infobip SDK (opens in a new tab) for your preferred programming language.
  4. Your sender. If you are in the free trial period, you can use Infobip's test sender, ServiceSMS. If you want to configure your custom sender, request a new number or an alphanumeric sender through the Infobip account (opens in a new tab) or using Infobip Numbers API (opens in a new tab).
  5. Destination - a phone number to which the message will be sent. If you are in the free trial period, you can only send messages to your verified phone number.

Implementation

Step 1: Send a simple text message using the /sms/3/messages endpoint

 curl -X POST https://api.infobip.com/sms/3/messages \
 -H 'Authorization: App {YOUR_API_KEY}'\
 -H 'Content-Type: application/json' \
 -d '{ \
   "messages": [ \
      { \
         "sender": "{YOUR_SENDER}", \
         "destinations": [ \
            { \
               "to": "{YOUR_DESTINATION}" \
            } \
         ], \
         "content": { \
            "text": "Congratulations on sending your first message.Go ahead and check the delivery report in the next step." \
         } \
      } \
   ] \
 }'

If you are using your phone number as a destination, the message should appear on your device shortly.

Step 2: Receive a delivery report using /sms/3/reports endpoint

Messaging is asynchronous by design. If you have successfully sent a message in the previous step, you should receive a response with a 200 status that contains a message ID in the body, for example:

{
  "bulkId": "2034072219640523072",
  "messages": [
    {
      "messageId": "2250be2d4219-3af1-78856-aabe-1362af1edfd2",
      "status": {
        "groupId": 1,
        "groupName": "PENDING",
        "id": 26,
        "name": "PENDING_ACCEPTED",
        "description": "Message sent to next instance"
      },
      "destination": "41793026727",
      "details": {
        "messageCount": 1
      }
    }
  ]
}

You can use the received message ID to fetch a delivery report for this particular message. Of course, if you track your messages in your system, you can send your own message ID when sending the message. Please note that the delivery report will be returned only once.

    curl -X GET https://api.infobip.com/sms/3/reports?messageId={RECEIVED_MESSAGE_ID} \
    -H 'Authorization: App {YOUR_API_KEY}'

If everything went smoothly, you should receive a response stating that the status of your message is DELIVERED_TO_HANDSET. You can find more details about response status and error codes by visiting the Response status and error codes (opens in a new tab) page.

Also, for each message you send, we offer the option to send a delivery report directly to your endpoint, so you do not need to pull it from our API. For more details, check the Receive outbound SMS message reports (opens in a new tab) section.

Step 3: That's it!

That's it! You have successfully sent an SMS message using Infobip API.

Useful links

Encountering issues

Contact our support

What's new? Check out

Release Notes

Unsure about a term? See

Glossary

Research panel

Help shape the future of our products