I have a problem when send SMS I get 200 http status but message is not received to my mobile.
THIS MY CODE
try {
// Create the connection to the Infobip API.
URL url = new URL(BASE_URL + "/sms/2/text/advanced");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", "App " + API_KEY);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
// connection.setRequestProperty("User-Agent", "Mozilla/4.76");
connection.setDoOutput(true);
// Create the SMS message JSON payload.
String payload = String.format("{\"messages\":[{\"from\":\"%s\",\"destinations\":[{\"to\":\"%s\"}],\"text\":\"%s\"}]}",
SENDER,
RECIPIENT,
MESSAGE_TEXT
);
// Write the payload to the request.
try (OutputStream os = connection.getOutputStream()) {
byte[] input = payload.getBytes("utf-8");
os.write(input, 0, input.length);
}
// Get the response from the API.
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println("Message sent successfully. Response Content: " + response.toString());
}
} else {
// Print the response content for error requests.
// Similar to the success case, adjust the parsing and print the full response content.
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) {
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println("Error sending message. Response Content: " + response.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
Response Code: 200
This is response:
Message sent successfully. Response Content: {"messages":[{"messageId":"3915723960824335774697","status":{"description":"Message sent to next instance","groupId":1,"groupName":"PENDING","id":26,"name":"PENDING_ACCEPTED"},"to":"970597086266"}]}
This response should be returned like this:
groupId: 3
groupName: DELIVERED
id: 5
name: DELIVERED_TO_HANDSET
description: Message delivered to handset
action: null
Some time has passed and I am putting my comment here to help others not lose too much time on this. I had a similar problem and while looking for some clues I found your question.
I was getting the same response when calling the API.
{
"messages": [
{
"messageId": "SOME_MESSAGE_ID",
"status": {
"description": "Message sent to next instance",
"groupId": 1,
"groupName": "PENDING",
"id": 26,
"name": "PENDING_ACCEPTED"
},
"to": "SOME_PHONE_NUMBER"
}
]
}
If you try to get some info about that messageID through the API again ( https://epqd3.api.infobip.com/sms/2/logs?messageId=THE_MESSAGE_ID ), you would get an empty response like:
{
"results": []
}
If you try to check the dashboard in Infobip, there is no such request/message.
If you try to make a request via Postman (with SMS body as plain text), all is good and you can see the message in the dashboard.
[Cause of the problem]
Turned out the problem was that the content of the SMS was not in PLAIN TEXT! It was more like a rendered HTML encoded string.
[Solution]
For me it was just making sure the body of the SMS is in PLAIN TEXT. That solved the problem for me.