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