Sample code for 30+ languages & platforms
Rust

Outlook Calendar List Calendars

See more Outlook Calendar Examples

Get all the user's calendars.

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 here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

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

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

let resp = chilkat::HttpResponse::new();
if http.http_no_body("GET", "https://graph.microsoft.com/v1.0/me/calendars", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Response status code = {}", resp.status_code());

// The HTTP request succeeded if the response status code = 200.
if resp.status_code() != 200 {
    println!("{}", resp.body_str());
    println!("Failed");
    return;
}

let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

// Here is a sample response:

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

// {
//     "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#me/calendars",
//     "value": [
//         {
//             "@odata.id": "https://graph.microsoft.com/v1.0/users('ddfcd489-628b-40d7-b48b-57002df800e5@1717622f-1d94-4d0c-9d74-709fad664b77')/calendars('AAMkAGI2TGuLAAA=')",
//             "id": "AAMkAGI2TGuLAAA=",
//             "name": "Calendar",
//             "color": "auto",
//             "changeKey": "nfZyf7VcrEKLNoU37KWlkQAAA0x0+w==",
//             "canShare":true,
//             "canViewPrivateItems":true,
//             "hexColor": "",
//             "canEdit":true,
//             "allowedOnlineMeetingProviders": [
//                 "teamsForBusiness"
//             ],
//             "defaultOnlineMeetingProvider": "teamsForBusiness",
//             "isTallyingResponses": true,
//             "isRemovable": false,
//             "owner":{
//                 "name":"Samantha Booth",
//                 "address":"samanthab@adatum.onmicrosoft.com"
//             }
//         }
//     ]
// }

let mut j: i32 = 0;
let mut count_j: i32 = 0;

let odata_context = json.string_of("\"@odata.context\"").unwrap_or_default();
let mut 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].hexColor").unwrap_or_default();
    let _ = json.bool_of("value[i].isDefaultCalendar");
    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].defaultOnlineMeetingProvider").unwrap_or_default();
    let _ = json.bool_of("value[i].isTallyingResponses");
    let _ = json.bool_of("value[i].isRemovable");
    let _ = json.string_of("value[i].owner.name").unwrap_or_default();
    let _ = json.string_of("value[i].owner.address").unwrap_or_default();
    j = 0;
    count_j = json.size_of_array("value[i].allowedOnlineMeetingProviders");
    while j < count_j {
        json.set_j(j);
        let _ = json.string_of("value[i].allowedOnlineMeetingProviders[j]").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}