Sample code for 30+ languages & platforms
Rust

SugarCRM Getting a Record

See more SugarCRM Examples

Gets a record from the Sugar instance using the //:record endpoint. In this example we get an Account record by it's ID, but only request the Name, Email, and Industry fields.

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 -H OAuth-Token:<access_token> -H Cache-Control:no-cache http://<site_url>/rest/v10/Accounts/<record_id>?fields=name,email1,industry

http.set_request_header("Cache-Control", "no-cache");
http.set_request_header("OAuth-Token", "<access_token>");

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("http://<site_url>/rest/v10/Accounts/<record_id>?fields=name,email1,industry", &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

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 = 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": "ab2222df-73da-0e92-6887-5705428f4d68",
//   "name": "Test Record",
//   "date_modified": "2016-04-06T15:03:21-04:00",
//   "industry": "",
//   "email1": "test@sugar.com",
//   "_acl": {
//     "fields": {}
//   },
//   "_module": "Accounts"
// }

// 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 name = j_resp.string_of("name").unwrap_or_default();
let date_modified = j_resp.string_of("date_modified").unwrap_or_default();
let industry = j_resp.string_of("industry").unwrap_or_default();
let email1 = j_resp.string_of("email1").unwrap_or_default();
let v_module = j_resp.string_of("_module").unwrap_or_default();