Rust Requires Chilkat v11.0.0+
Rust
Clickatell HTTP API: Send an SMS with query parameters
See more Clickatell Examples
Use an SMS integration configured for HTTP in the Clickatell Portal. The endpoint takes apiKey, to, and content as query parameters. Pass raw values to Chilkat so it can encode spaces, ampersands, and other reserved characters. Supply a country code and phone number as digits. Set from when your two-way integration requires a sender.
The URL contains the API key, recipient, and message text. Keep full request URLs out of logs and browser history. Check the per-message result after HTTP 202. If the connection is interrupted, check the Portal message report before resending. For the header-authenticated JSON workflow, see Send an SMS with One API.
Chilkat Rust Downloads
let mut success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
// Use the key issued for this HTTP integration. Chilkat encodes each query value.
let query = chilkat::HttpRequest::new();
query.set_http_verb("GET");
query.add_header("Accept", "application/json");
query.add_param("apiKey", "HTTP_API_KEY");
query.add_param("to", "PHONE_NUMBER");
query.add_param("content", "Test message: pickup between 2 & 4.");
let sender = String::new();
if sender != "" {
query.add_param("from", &sender);
}
let resp = chilkat::HttpResponse::new();
success = http.http_req("https://platform.clickatell.com/messages/http/send", &query, &resp).is_ok();
if resp.status_code() == 0 {
println!("The send outcome is unknown. Check the message report before resending.");
return;
}
let reply = chilkat::JsonObject::new();
let parsed = reply.load(&resp.body_str()).is_ok();
if (!success) || ((resp.status_code() != 202)) {
println!("Clickatell returned HTTP {}", resp.status_code());
if parsed {
if reply.has_member("errorDescription") {
println!("{}", reply.string_of("errorDescription").unwrap_or_default());
}
}
return;
}
if !parsed {
println!("Expected a JSON response.");
return;
}
// A request-level error applies to the submission as a whole.
if reply.has_member("errorCode") {
if !reply.is_null_of("errorCode") {
println!("Submission error {} {}", reply.string_of("errorCode").unwrap_or_default(), reply.string_of("errorDescription").unwrap_or_default());
return;
}
}
let count = reply.size_of_array("messages");
if count <= 0 {
println!("No recipient results returned. Check the message report before resending.");
return;
}
let mut i = 0;
while i < count {
reply.set_i(i);
let result_number = i + 1;
// JsonTypeOf returns 5 for a JSON boolean.
if reply.json_type_of("messages[i].accepted") != 5 {
println!("Result {} has no acceptance flag.", result_number);
} else {
if reply.bool_of("messages[i].accepted") {
let message_id = reply.string_of("messages[i].apiMessageId").unwrap_or_default();
if (reply.json_type_of("messages[i].apiMessageId") != 1) || (message_id == "") {
println!("Result {} was accepted without a tracking ID.", result_number);
} else {
println!("Result {} accepted. Message ID: {}", result_number, message_id);
}
} else {
println!("Result {} rejected: {} {}", result_number, reply.string_of("messages[i].errorCode").unwrap_or_default(), reply.string_of("messages[i].errorDescription").unwrap_or_default());
}
}
i = i + 1;
}