Sample code for 30+ languages & platforms
Rust

MS Graph Calendars List

See more Microsoft Calendar Examples

Get all the user's calendars (/calendars navigation property), get the calendars from the default calendar group or from a specific calendar group.

For more details, see https://docs.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// Use your previously obtained access token as shown here:
//    Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.

let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/msGraphCalendar.json").is_err() {
    println!("{}", json_token.last_error_text());
    return;
}

http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());

// Send a GET request to https://graph.microsoft.com/v1.0/me/calendars
let Ok(str_response) = http.quick_get_str("https://graph.microsoft.com/v1.0/me/calendars") else {
    println!("{}", http.last_error_text());
    return;
};

let json = chilkat::JsonObject::new();
let _ = json.load(&str_response);
json.set_emit_compact(false);

if http.last_status() != 200 {
    println!("{}", json.emit().unwrap_or_default());
    println!("Failed, response status code = {}", http.last_status());
    return;
}

println!("{}", json.emit().unwrap_or_default());

// Sample output:

// {
//   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars",
//   "value": [
//     {
//       "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA",
//       "name": "Calendar",
//       "color": "auto",
//       "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAAAAAiEQ==",
//       "canShare": true,
//       "canViewPrivateItems": true,
//       "canEdit": true,
//       "owner": {
//         "name": "...",
//         "address": "outlook_3A33FCEB9B74CC15@outlook.com"
//       }
//     },
//     {
//       "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==",
//       "name": "Work",
//       "color": "auto",
//       "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClHjDcA==",
//       "canShare": true,
//       "canViewPrivateItems": true,
//       "canEdit": true,
//       "owner": {
//         "name": "...",
//         "address": "outlook_3A33FCEB9B74CC15@outlook.com"
//       }
//     }
//   ]
// }
// 
// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

let mut i: i32 = 0;

let odata_context = json.string_of("\"@odata.context\"").unwrap_or_default();
i = 0;
let count_i = json.size_of_array("value");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("value[i].id").unwrap_or_default();
    let _ = json.string_of("value[i].name").unwrap_or_default();
    let _ = json.string_of("value[i].color").unwrap_or_default();
    let _ = json.string_of("value[i].changeKey").unwrap_or_default();
    let _ = json.bool_of("value[i].canShare");
    let _ = json.bool_of("value[i].canViewPrivateItems");
    let _ = json.bool_of("value[i].canEdit");
    let _ = json.string_of("value[i].owner.name").unwrap_or_default();
    let _ = json.string_of("value[i].owner.address").unwrap_or_default();
    i = i + 1;
}

println!("Success.");