Sample code for 30+ languages & platforms
Rust

SMSAPI - Add Subuser Account

See more SMSAPI Examples

Adds a new sub-user account.

Chilkat Rust Downloads

Rust

// 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 https://api.smsapi.com/subusers -i -H "Authorization: Bearer token_api_oauth" \ 
// -H  "Content-Type: application/json" -X POST \
// -d '{"credentials": { "username": "User_name","password" :"Smsapi_panel_password","api_password":"api_password"},
// "active":"1","description":"description","points":{"from_account":"2","per_month":"2"}}'

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "credentials": {
//     "username": "User_name",
//     "password": "Smsapi_panel_password",
//     "api_password": "api_password"
//   },
//   "active": "1",
//   "description": "description",
//   "points": {
//     "from_account": "2",
//     "per_month": "2"
//   }
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("credentials.username", "User_name");
let _ = json.update_string("credentials.password", "Smsapi_panel_password123");
let _ = json.update_string("credentials.api_password", "api_Password123");
let _ = json.update_string("active", "1");
let _ = json.update_string("description", "description");
let _ = json.update_string("points.from_account", "2");
let _ = json.update_string("points.per_month", "2");

// Adds the "Authorization: Bearer token_api_oauth" header.
http.set_auth_token("token_api_oauth");

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.smsapi.com/subusers", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", resp.header());
    println!("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "username": "subuser",
//   "limit": 0,
//   "month_limit": 0,
//   "senders": 0,
//   "phonebook": 0,
//   "active": false,
//   "info": "unknown"
// }

// 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 username = j_resp.string_of("username").unwrap_or_default();
let limit = j_resp.int_of("limit");
let month_limit = j_resp.int_of("month_limit");
let senders = j_resp.int_of("senders");
let phonebook = j_resp.int_of("phonebook");
let active = j_resp.bool_of("active");
let info = j_resp.string_of("info").unwrap_or_default();