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

MS Graph Calendar Create Event

See more Microsoft Calendar Examples

Creates a new event in a specified calendar.

For more details, see https://docs.microsoft.com/en-us/graph/api/calendar-post-events?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
// Use this online tool to generate the code from sample JSON: 
// Generate Code to Create JSON

// {
//   "subject": "Let's go for lunch",
//   "body": {
//     "contentType": "HTML",
//     "content": "Does mid month work for you?"
//   },
//   "start": {
//       "dateTime": "2019-11-15T12:00:00",
//       "timeZone": "Pacific Standard Time"
//   },
//   "end": {
//       "dateTime": "2019-11-15T14:00:00",
//       "timeZone": "Pacific Standard Time"
//   },
//   "location":{
//       "displayName":"Harry's Bar"
//   },
//   "attendees": [
//     {
//       "emailAddress": {
//         "address":"adelev@contoso.onmicrosoft.com",
//         "name": "Adele Vance"
//       },
//       "type": "required"
//     }
//   ]
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("subject", "Let's go for lunch");
let _ = json.update_string("body.contentType", "HTML");
let _ = json.update_string("body.content", "Does mid month work for you?");
let _ = json.update_string("start.dateTime", "2019-11-15T12:00:00");
let _ = json.update_string("start.timeZone", "Pacific Standard Time");
let _ = json.update_string("end.dateTime", "2019-11-15T14:00:00");
let _ = json.update_string("end.timeZone", "Pacific Standard Time");
let _ = json.update_string("location.displayName", "Harry's Bar");
let _ = json.update_string("attendees[0].emailAddress.address", "adelev@contoso.onmicrosoft.com");
let _ = json.update_string("attendees[0].emailAddress.name", "Adele Vance");
let _ = json.update_string("attendees[0].type", "required");

// POST the JSON to https://graph.microsoft.com/v1.0/me/calendars/{id}/events
// This is posting to a calendar in the default calendarGroup.

// Specify the calendar id
let _ = http.set_url_var("id", "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", &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:
// (See code for parsing this response below..)

// {
//   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars('AQMkADAwATM0MDAAMS ... AClEpRTgAAAA%3D%3D')/events/$entity",
//   "@odata.etag": "W/\"5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==\"",
//   "id": "AQMkADAwAT ... ApRZ7JkAAAA=",
//   "createdDateTime": "2019-04-26T14:31:39.8791929Z",
//   "lastModifiedDateTime": "2019-04-26T14:31:41.2753537Z",
//   "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==",
//   "categories": [
//   ],
//   "originalStartTimeZone": "Pacific Standard Time",
//   "originalEndTimeZone": "Pacific Standard Time",
//   "iCalUId": "040000008200E00074C5B7101A82E00800000000F05DF1C23CFCD40100000000000000001000000009911D155F71EF42A230FEBFE5F7486A",
//   "reminderMinutesBeforeStart": 15,
//   "isReminderOn": true,
//   "hasAttachments": false,
//   "subject": "Let's go for lunch",
//   "bodyPreview": "Does mid month work for you?",
//   "importance": "normal",
//   "sensitivity": "normal",
//   "isAllDay": false,
//   "isCancelled": false,
//   "isOrganizer": true,
//   "responseRequested": true,
//   "seriesMasterId": null,
//   "showAs": "busy",
//   "type": "singleInstance",
//   "webLink": "https://outlook.live.com/owa/?itemid=AQMkADAwATM0MDAAMS1iNTcwL...pRZ7JkAAAA%3D&exvsurl=1&path=/calendar/item",
//   "onlineMeetingUrl": null,
//   "recurrence": null,
//   "responseStatus": {
//     "response": "organizer",
//     "time": "0001-01-01T00:00:00Z"
//   },
//   "body": {
//     "contentType": "html",
//     "content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes mid month work for you?\r\n</body>\r\n</html>\r\n"
//   },
//   "start": {
//     "dateTime": "2019-11-15T12:00:00.0000000",
//     "timeZone": "Pacific Standard Time"
//   },
//   "end": {
//     "dateTime": "2019-11-15T14:00:00.0000000",
//     "timeZone": "Pacific Standard Time"
//   },
//   "location": {
//     "displayName": "Harry's Bar",
//     "locationType": "default",
//     "uniqueId": "Harry's Bar",
//     "uniqueIdType": "private"
//   },
//   "locations": [
//     {
//       "displayName": "Harry's Bar",
//       "locationType": "default",
//       "uniqueId": "Harry's Bar",
//       "uniqueIdType": "private"
//     }
//   ],
//   "attendees": [
//     {
//       "type": "required",
//       "status": {
//         "response": "none",
//         "time": "0001-01-01T00:00:00Z"
//       },
//       "emailAddress": {
//         "name": "Adele Vance",
//         "address": "adelev@contoso.onmicrosoft.com"
//       }
//     }
//   ],
//   "organizer": {
//     "emailAddress": {
//       "name": "Matt",
//       "address": "outlook_3A33FCEB9B74CC15@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 odata_etag = json.string_of("\"@odata.etag\"").unwrap_or_default();
let id = json.string_of("id").unwrap_or_default();
let created_date_time = json.string_of("createdDateTime").unwrap_or_default();
let last_modified_date_time = json.string_of("lastModifiedDateTime").unwrap_or_default();
let change_key = json.string_of("changeKey").unwrap_or_default();
let original_start_time_zone = json.string_of("originalStartTimeZone").unwrap_or_default();
let original_end_time_zone = json.string_of("originalEndTimeZone").unwrap_or_default();
let i_cal_u_id = json.string_of("iCalUId").unwrap_or_default();
let reminder_minutes_before_start = json.int_of("reminderMinutesBeforeStart");
let is_reminder_on = json.bool_of("isReminderOn");
let has_attachments = json.bool_of("hasAttachments");
let subject = json.string_of("subject").unwrap_or_default();
let body_preview = json.string_of("bodyPreview").unwrap_or_default();
let importance = json.string_of("importance").unwrap_or_default();
let sensitivity = json.string_of("sensitivity").unwrap_or_default();
let is_all_day = json.bool_of("isAllDay");
let is_cancelled = json.bool_of("isCancelled");
let is_organizer = json.bool_of("isOrganizer");
let response_requested = json.bool_of("responseRequested");
let series_master_id = json.string_of("seriesMasterId").unwrap_or_default();
let show_as = json.string_of("showAs").unwrap_or_default();
let mut type_ = json.string_of("type").unwrap_or_default();
let web_link = json.string_of("webLink").unwrap_or_default();
let online_meeting_url = json.string_of("onlineMeetingUrl").unwrap_or_default();
let recurrence = json.string_of("recurrence").unwrap_or_default();
let response_status_response = json.string_of("responseStatus.response").unwrap_or_default();
let response_status_time = json.string_of("responseStatus.time").unwrap_or_default();
let body_content_type = json.string_of("body.contentType").unwrap_or_default();
let body_content = json.string_of("body.content").unwrap_or_default();
let start_date_time = json.string_of("start.dateTime").unwrap_or_default();
let start_time_zone = json.string_of("start.timeZone").unwrap_or_default();
let end_date_time = json.string_of("end.dateTime").unwrap_or_default();
let end_time_zone = json.string_of("end.timeZone").unwrap_or_default();
let location_display_name = json.string_of("location.displayName").unwrap_or_default();
let location_location_type = json.string_of("location.locationType").unwrap_or_default();
let location_unique_id = json.string_of("location.uniqueId").unwrap_or_default();
let location_unique_id_type = json.string_of("location.uniqueIdType").unwrap_or_default();
let organizer_email_address_name = json.string_of("organizer.emailAddress.name").unwrap_or_default();
let organizer_email_address_address = json.string_of("organizer.emailAddress.address").unwrap_or_default();
let mut i = 0;
let mut count_i = json.size_of_array("categories");
while i < count_i {
    json.set_i(i);
    // ...
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("locations");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("locations[i].displayName").unwrap_or_default();
    let _ = json.string_of("locations[i].locationType").unwrap_or_default();
    let _ = json.string_of("locations[i].uniqueId").unwrap_or_default();
    let _ = json.string_of("locations[i].uniqueIdType").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("attendees");
while i < count_i {
    json.set_i(i);
    type_ = json.string_of("attendees[i].type").unwrap_or_default();
    let _ = json.string_of("attendees[i].status.response").unwrap_or_default();
    let _ = json.string_of("attendees[i].status.time").unwrap_or_default();
    let _ = json.string_of("attendees[i].emailAddress.name").unwrap_or_default();
    let _ = json.string_of("attendees[i].emailAddress.address").unwrap_or_default();
    i = i + 1;
}

println!("Success.");