Preview an SMS using Infobip API
As an outcome of this tutorial, you will be able to check the message count and whether there are any characters left in the message. In the case of international communication, you can also review the original text and preview transliteration for mobiles not supporting that particular character set.
Prerequisites
- 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).
- Infobip API key with
sms:message:sendscope. Find out more about scopes in API Authorization. - Your favorite HTTP client. In this example, we will use
curl. Additionally, you can choose the official Infobip SDK for your preferred programming language. - Sender. If in the free trial period, 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 use the Infobip Numbers API (opens in a new tab). - Destination - a phone number to which the message will be sent. If in the free trial period, you can only send messages to your verified phone number.
Send a request to preview the SMS
Use the Preview SMS message (opens in a new tab) endpoint to receive a response with the preview of your SMS.
curl -L -g 'https://{baseUrl}/sms/1/preview' \
-H 'Authorization: {authorization}' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"text": "Ni se imaginan la cara que puso Martín cuando le pasó lo que les voy a contar, que les aseguro que es la pura verdad. Una mañana mientras Martín iba a la escuela, sintió que algo saltaba dentro de su mochila, primero se paró quieto, muy quietito, y la mochi volvió a moverse. Sus ojos se abrieron cada vez más grandotes.",
"languageCode": "ES",
"transliteration": "NON_UNICODE"
}'Key points:
- Use the
transliterationfield to add a language code (opens in a new tab) or aNON_UNICODEvalue if you want to preview a fallback message for phones that don't support that particular character set. - Use the
languageCodefield to add a language code or set it toAUTODETECTto let the Infobip platform select the character set based on the message content.
See the response with the SMS preview
Once you run the code provided in the previous section, you should see a 200 OK response where you can preview your message and its variations. We chose to preview an excerpt from a Spanish children's book and selected the appropriate character set (ES). Additionally, for those whose phones don't support Spanish character set, we chose a NON_UNICODE version to show on their devices.
{
"originalText": "Ni se imaginan la cara que puso Martín cuando le pasó lo que les voy a contar, que les aseguro que es la pura verdad. Una mañana mientras Martín iba a la escuela, sintió que algo saltaba dentro de su mochila, primero se paró quieto, muy quietito, y la mochi volvió a moverse. Sus ojos se abrieron cada vez más grandotes.",
"previews": [
{
"textPreview": "Ni se imaginan la cara que puso Martín cuando le pasó lo que les voy a contar, que les aseguro que es la pura verdad. Una mañana mientras Martín iba a la escuela, sintió que algo saltaba dentro de su mochila, primero se paró quieto, muy quietito, y la mochi volvió a moverse. Sus ojos se abrieron cada vez más grandotes.",
"messageCount": 5,
"charactersRemaining": 15,
"configuration": {}
},
{
"textPreview": "Ni se imaginan la cara que puso Martín cuando le pasó lo que les voy a contar, que les aseguro que es la pura verdad. Una mañana mientras Martín iba a la escuela, sintió que algo saltaba dentro de su mochila, primero se paró quieto, muy quietito, y la mochi volvió a moverse. Sus ojos se abrieron cada vez más grandotes.",
"messageCount": 3,
"charactersRemaining": 120,
"configuration": {
"language": {
"languageCode": "ES"
}
}
},
{
"textPreview": "Ni se imaginan la cara que puso Martin cuando le paso lo que les voy a contar, que les aseguro que es la pura verdad. Una mañana mientras Martin iba a la escuela, sintio que algo saltaba dentro de su mochila, primero se paro quieto, muy quietito, y la mochi volvio a moverse. Sus ojos se abrieron cada vez mas grandotes.",
"messageCount": 3,
"charactersRemaining": 139,
"configuration": {
"transliteration": "NON_UNICODE"
}
}
]
}