Rust
Rust
SugarCRM Filtering Records
See more SugarCRM Examples
Export records and filter.Chilkat Rust Downloads
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("filter[0].$or[0].name.$starts", "A");
let _ = json_req.update_string("filter[0].$or[1].name.$starts", "b");
let _ = json_req.update_number("max_num", "2");
let _ = json_req.update_number("offset", "0");
let _ = json_req.update_string("fields", "id");
let _ = json_req.update_string("order_by", "date_entered");
let _ = json_req.update_bool("favorites", false);
let _ = json_req.update_bool("my_items", false);
// The JSON request body created by the above code:
// {
// "filter": [
// {
// "$or": [
// {
// "name": {
// "$starts": "A"
// }
// },
// {
// "name": {
// "$starts": "b"
// }
// }
// ]
// }
// ],
// "max_num": 2,
// "offset": 0,
// "fields": "id",
// "order_by": "date_entered",
// "favorites": false,
// "my_items": false
// }
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/filter", &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 next_offset = json.int_of("next_offset");
i = 0;
let count_i = json.size_of_array("records");
while i < count_i {
json.set_i(i);
let _ = json.string_of("records[i].id").unwrap_or_default();
let _ = json.string_of("records[i].date_modified").unwrap_or_default();
let _ = json.string_of("records[i]._module").unwrap_or_default();
i = i + 1;
}
// A sample JSON response body that is parsed by the above code:
// {
// "next_offset": 2,
// "records": [
// {
// "id": "f16760a4-3a52-f77d-1522-5703ca28925f",
// "date_modified": "2016-04-05T10:23:28-04:00",
// "_acl": {
// "fields": {}
// },
// "_module": "Accounts"
// },
// {
// "id": "ec409fbb-2b22-4f32-7fa1-5703caf78dc3",
// "date_modified": "2016-04-05T10:23:28-04:00",
// "_acl": {
// "fields": {}
// },
// "_module": "Accounts"
// }
// ]
// }
println!("Example Completed.");