Java Requires Chilkat v11.0.0+
Java
Clickatell One API: Schedule a time-limited SMS reminder
See more Clickatell Examples
Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.
Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Http http = new Http();
http.setRequireSslCertVerify(true);
// Load the key for this One API integration from your application configuration.
http.setRequestHeader("Authorization", "ONE_API_KEY");
http.setRequestHeader("Accept", "application/json");
DateTime schedule = new DateTime();
schedule.setFromCurrentSystemTime();
schedule.addSeconds(900);
String sendAt = schedule.getAsTimestamp(false);
JsonObject body = new JsonObject();
body.updateString("messages[0].channel", "sms");
body.updateString("messages[0].to", "PHONE_NUMBER");
body.updateString("messages[0].content", "Appointment reminder: please check in at reception.");
body.updateString("messages[0].scheduledDeliveryTime", sendAt);
body.updateInt("messages[0].validityPeriod", 60);
String sender = "";
if (!"".equals(sender)) {
body.updateString("messages[0].from", sender);
}
System.out.println("Requested send time (UTC): " + sendAt);
HttpResponse resp = new HttpResponse();
boolean sent;
try {
http.httpJson("POST", "https://platform.clickatell.com/v1/message", body, "application/json", resp);
sent = true;
} catch (ChilkatException e) {
sent = false;
}
if (resp.getStatusCode() == 0) {
System.out.println("No HTTP response. Check the message report before resending.");
return;
}
JsonObject reply = new JsonObject();
boolean parsed;
try {
reply.load(resp.getBodyStr());
parsed = true;
} catch (ChilkatException e) {
parsed = false;
}
if ((!sent) || (resp.getStatusCode() != 202)) {
System.out.println("Send returned HTTP " + resp.getStatusCode());
if (reply.hasMember("error.description")) {
System.out.println(reply.stringOf("error.description"));
}
return;
}
if (reply.hasMember("error.code")) {
if (!reply.isNullOf("error.code")) {
System.out.println("Submission error " + reply.stringOf("error.code") + " " + reply.stringOf("error.description"));
return;
}
}
// HTTP acceptance and the recipient result are separate checks.
if ((!parsed) || (reply.jsonTypeOf("messages[0].accepted") != 5)) {
System.out.println("Missing recipient result. Check the message report.");
return;
}
if (!reply.boolOf("messages[0].accepted")) {
System.out.println("Message rejected: " + reply.stringOf("messages[0].error.code") + " " + reply.stringOf("messages[0].error.description"));
return;
}
if (reply.jsonTypeOf("messages[0].apiMessageId") != 1) {
System.out.println("Accepted without a message ID. Check the message report.");
return;
}
System.out.println("Accepted. Message ID: " + reply.stringOf("messages[0].apiMessageId"));
}
}