Sample code for 30+ languages & platforms
Rust

SMSAPI - Edit a Subuser Account

See more SMSAPI Examples

Modify a 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 -X PUT -H "Content-Type: application/json" \
// -H "Authorization: Bearer token_api_oauth" -d\
// '{"credentials":{"password":"Customer_portal_password","api_password":"API_password"}, 
// "active":"1","description":"Test description","points":{"from_account":"2","per_month":"2"}}'
// 'https://api.smsapi.com/subusers/{subuser_id}'

// 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": {
//     "password": "Customer_portal_password",
//     "api_password": "API_password"
//   },
//   "active": "1",
//   "description": "Test description",
//   "points": {
//     "from_account": "2",
//     "per_month": "2"
//   }
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("credentials.password", "new_Password_1234");
let _ = json.update_string("credentials.api_password", "new_API_password_1234");
let _ = json.update_string("active", "1");
let _ = json.update_string("description", "Test description");
let _ = json.update_string("points.from_account", "3");
let _ = json.update_string("points.per_month", "3");

// 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_request_body = chilkat::StringBuilder::new();
let _ = json.emit_sb(&sb_request_body);

// In this example, the subuser_id is 5F8BB03E6436384B0AB36F1B
let resp = chilkat::HttpResponse::new();
if http.http_sb("PUT", "https://api.smsapi.com/subusers/5F8BB03E6436384B0AB36F1B", &sb_request_body, "utf-8", "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)

// {
//   "id": "5F8BB03E6436384B0AB36F1B",
//   "username": "TestUser",
//   "active": true,
//   "description": "Test description",
//   "points": {
//     "from_account": 3.0,
//     "per_month": 3.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 id = j_resp.string_of("id").unwrap_or_default();
let username = j_resp.string_of("username").unwrap_or_default();
let active = j_resp.bool_of("active");
let description = j_resp.string_of("description").unwrap_or_default();
let points_from_account = j_resp.string_of("points.from_account").unwrap_or_default();
let points_per_month = j_resp.string_of("points.per_month").unwrap_or_default();