Rust
Rust
SMSAPI - Get User Account Information
See more SMSAPI Examples
Get a list of subusers.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Implements the following CURL command:
// curl -i -H "Authorization: Bearer token_api_oauth" \
// -H "Content-Type: application/json" -X GET https://api.smsapi.com/subusers
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Adds the "Authorization: Bearer token_api_oauth" header.
http.set_auth_token("token_api_oauth");
http.set_request_header("Content-Type", "application/json");
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.smsapi.com/subusers", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
let jarr_resp = chilkat::JsonArray::new();
let _ = jarr_resp.load_sb(&sb_response_body);
jarr_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", jarr_resp.emit().unwrap_or_default());
let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// [
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser1",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// },
// {
// "id": "5A5359173738303F2F95B7E2",
// "username": "subuser2",
// "active": "true",
// "description": "null",
// "from_account": "10.0000",
// "per_month": "0"
// }
// ]
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut i = 0;
let count_i = jarr_resp.size();
while i < count_i {
let json = jarr_resp.object_at(i).unwrap();
let _ = json.string_of("id").unwrap_or_default();
let _ = json.string_of("username").unwrap_or_default();
let _ = json.string_of("active").unwrap_or_default();
let _ = json.string_of("description").unwrap_or_default();
let _ = json.string_of("from_account").unwrap_or_default();
let _ = json.string_of("per_month").unwrap_or_default();
i = i + 1;
}