Sample code for 30+ languages & platforms
Rust

SugarCRM Create a Record List

See more SugarCRM Examples

Create a record list in Sugar consisting of a set of ids.

Chilkat Rust Downloads

Rust

let rest = chilkat::Rest::new();

if rest.connect("your.site.domain", 443, true, true).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

let _ = rest.add_header("Cache-Control", "no-cache");
let _ = rest.add_header("OAuth-Token", "<access_token>");

// The following code creates the JSON request body.
// The JSON created by this code is shown below.
let json_req = chilkat::JsonObject::new();
let _ = json_req.update_string("records[0]", "f16760a4-3a52-f77d-1522-5703ca28925f");
let _ = json_req.update_string("records[1]", "ec409fbb-2b22-4f32-7fa1-5703caf78dc3");

// The JSON request body created by the above code:

// {
//   "records": [
//     "f16760a4-3a52-f77d-1522-5703ca28925f",
//     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
//   ]
// }

let sb_req = chilkat::StringBuilder::new();
let _ = json_req.emit_sb(&sb_req);

let _ = rest.add_header("Content-Type", "application/json");

let sb_json = chilkat::StringBuilder::new();
if rest.full_request_sb("POST", "/rest/v10/Accounts/record_list", &sb_req, &sb_json).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

if rest.response_status_code() != 200 {
    println!("Received error response code: {}", rest.response_status_code());
    println!("Response body:");
    println!("{}", sb_json.get_as_string().unwrap_or_default());
    return;
}

let json = chilkat::JsonObject::new();
let _ = json.load_sb(&sb_json);

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
let mut i: i32 = 0;

let id = json.string_of("id").unwrap_or_default();
let assigned_user_id = json.string_of("assigned_user_id").unwrap_or_default();
let module_name = json.string_of("module_name").unwrap_or_default();
let date_modified = json.string_of("date_modified").unwrap_or_default();
i = 0;
let count_i = json.size_of_array("records");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("records[i]").unwrap_or_default();
    i = i + 1;
}

// A sample JSON response body that is parsed by the above code:

// {
//   "id": "ef963176-4845-bc55-b03e-570430b4173c",
//   "assigned_user_id": "1",
//   "module_name": "Accounts",
//   "records": [
//     "f16760a4-3a52-f77d-1522-5703ca28925f",
//     "ec409fbb-2b22-4f32-7fa1-5703caf78dc3"
//   ],
//   "date_modified": "2016-04-05 21:39:19"
// }

println!("Example Completed.");