Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

MS Graph Create Calendar

See more Microsoft Calendar Examples

Creates a new calendar.

For more details, see https://docs.microsoft.com/en-us/graph/api/user-post-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());

// Create a JSON body for the HTTP POST
// {
//   "name": "Work"
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("name", "Work");

// POST the JSON to https://graph.microsoft.com/v1.0/me/calendars
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/me/calendars", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let _ = json.load(&resp.body_str());
json.set_emit_compact(false);

if resp.status_code() != 201 {
    println!("{}", json.emit().unwrap_or_default());
    println!("Failed, response status code = {}", resp.status_code());
    return;
}

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

// A sample response:
// {
//   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars/$entity",
//   "id": "AQMkAD...TgAAAA==",
//   "name": "Work",
//   "color": "auto",
//   "changeKey": "5+vF7T...HjDcA==",
//   "canShare": true,
//   "canViewPrivateItems": true,
//   "canEdit": true,
//   "owner": {
//     "name": "...",
//     "address": "outlook_3A33...4CC15@outlook.com"
//   }
// }

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

let odata_context = json.string_of("\"@odata.context\"").unwrap_or_default();
let id = json.string_of("id").unwrap_or_default();
let name = json.string_of("name").unwrap_or_default();
let color = json.string_of("color").unwrap_or_default();
let change_key = json.string_of("changeKey").unwrap_or_default();
let can_share = json.bool_of("canShare");
let can_view_private_items = json.bool_of("canViewPrivateItems");
let can_edit = json.bool_of("canEdit");
let owner_name = json.string_of("owner.name").unwrap_or_default();
let owner_address = json.string_of("owner.address").unwrap_or_default();

println!("Success.");