Sample code for 30+ languages & platforms
Rust

Outlook Calendar List Events

See more Outlook Calendar Examples

Retrieve a list of events in a calendar.

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());

// Specify the ID of the calendar to list.
let calendar_id = "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA".to_string();

let _ = http.set_url_var("id", &calendar_id);

// To list the events in the default calendar, use the following URL: https://graph.microsoft.com/v1.0/me/calendars/events

let resp = chilkat::HttpResponse::new();
if http.http_no_body("GET", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", &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

// {
//   "value": [
//     {
//       "originalStartTimeZone": "originalStartTimeZone-value",
//       "originalEndTimeZone": "originalEndTimeZone-value",
//       "responseStatus": {
//         "response": "",
//         "time": "datetime-value"
//       },
//       "iCalUId": "iCalUId-value",
//       "reminderMinutesBeforeStart": 99,
//       "isReminderOn": true
//     }
//   ]
// }

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].originalStartTimeZone").unwrap_or_default();
    let _ = json.string_of("value[i].originalEndTimeZone").unwrap_or_default();
    let _ = json.string_of("value[i].responseStatus.response").unwrap_or_default();
    let _ = json.string_of("value[i].responseStatus.time").unwrap_or_default();
    let _ = json.string_of("value[i].iCalUId").unwrap_or_default();
    let _ = json.int_of("value[i].reminderMinutesBeforeStart");
    let _ = json.bool_of("value[i].isReminderOn");
    i = i + 1;
}