Unicode C++
Unicode C++
Outlook Calendar Create an Event
See more Outlook Calendar Examples
Create an event in the specified time zone, and assign the event an optional transactionId value.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkCrypt2W.h>
#include <CkHttpResponseW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).
CkJsonObjectW jsonToken;
success = jsonToken.LoadFile(L"qa_data/tokens/outlookCalendar.json");
if (success == false) {
wprintf(L"%s\n",jsonToken.lastErrorText());
return;
}
http.put_AuthToken(jsonToken.stringOf(L"access_token"));
// Send the following POST:
// POST https://graph.microsoft.com/v1.0/me/events
// Prefer: outlook.timezone="Pacific Standard Time"
// Content-type: application/json
//
// {
// "subject": "Let's go for lunch",
// "body": {
// "contentType": "HTML",
// "content": "Does noon work for you?"
// },
// "start": {
// "dateTime": "2017-04-15T12:00:00",
// "timeZone": "Pacific Standard Time"
// },
// "end": {
// "dateTime": "2017-04-15T14:00:00",
// "timeZone": "Pacific Standard Time"
// },
// "location":{
// "displayName":"Harry's Bar"
// },
// "attendees": [
// {
// "emailAddress": {
// "address":"samanthab@contoso.onmicrosoft.com",
// "name": "Samantha Booth"
// },
// "type": "required"
// }
// ],
// "allowNewTimeProposals": true,
// "transactionId":"7E163156-7762-4BEB-A1C6-729EA81755A7"
// }
// Build the JSON body of the POST.
CkJsonObjectW json;
json.UpdateString(L"subject",L"Let's go for lunch");
json.UpdateString(L"body.contentType",L"HTML");
json.UpdateString(L"body.content",L"Does noon work for you?");
json.UpdateString(L"start.dateTime",L"2021-05-15T12:00:00");
json.UpdateString(L"start.timeZone",L"Pacific Standard Time");
json.UpdateString(L"end.dateTime",L"2021-05-15T14:00:00");
json.UpdateString(L"end.timeZone",L"Pacific Standard Time");
json.UpdateString(L"location.displayName",L"Harry's Bar");
json.UpdateString(L"attendees[0].emailAddress.address",L"samanthab@contoso.onmicrosoft.com");
json.UpdateString(L"attendees[0].emailAddress.name",L"Samantha Booth");
json.UpdateString(L"attendees[0].type",L"required");
json.UpdateBool(L"allowNewTimeProposals",true);
// Generate a UUID.
CkCrypt2W crypt;
json.UpdateString(L"transactionId",crypt.generateUuid());
// Add the "Prefer" request header.
http.SetRequestHeader(L"Prefer",L"outlook.timezone=\"Pacific Standard Time\"");
// Send the HTTP POST
CkHttpResponseW resp;
success = http.HttpJson(L"POST",L"https://graph.microsoft.com/v1.0/me/events",json,L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
wprintf(L"Response status code = %d\n",resp.get_StatusCode());
CkJsonObjectW jResp;
jResp.Load(resp.bodyStr());
jResp.put_EmitCompact(false);
wprintf(L"%s\n",jResp.emit());
// The send succeeded if the response status code = 201.
if (resp.get_StatusCode() != 201) {
wprintf(L"Failed\n");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('user%40example.com')/events/$entity",
// "@odata.etag": "W/\"5+vF7TKKdE6bGCRqXyl2PQAEaGQgcw==\"",
// "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgENAAAA5_vF7TKKdE6bGCRqXyl2PQAEaDkEcAAAAA==",
// "createdDateTime": "2021-04-18T23:38:52.1979259Z",
// "lastModifiedDateTime": "2021-04-18T23:38:53.3747647Z",
// "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAEaGQgcw==",
// "categories": [
// ],
// "transactionId": "1d12b565-3ca3-4ed8-b3f9-e8a14ac3ac17",
// "originalStartTimeZone": "Pacific Standard Time",
// "originalEndTimeZone": "Pacific Standard Time",
// "iCalUId": "040000008200E00074C5B7101A82E00800000000EF0328FDAB34D7010000000000000000100000004478DD5948382543AFD1B52C25E88C02",
// "reminderMinutesBeforeStart": 15,
// "isReminderOn": true,
// "hasAttachments": false,
// "subject": "Let's go for lunch",
// "bodyPreview": "Does noon 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=AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5%2BvF7TKKdE6bGCRqXyl2PQAAAgENAAAA5%2BvF7TKKdE6bGCRqXyl2PQAEaDkEcAAAAA%3D%3D&exvsurl=1&path=/calendar/item",
// "onlineMeetingUrl": null,
// "isOnlineMeeting": false,
// "onlineMeetingProvider": "unknown",
// "allowNewTimeProposals": true,
// "isDraft": false,
// "hideAttendees": false,
// "recurrence": null,
// "onlineMeeting": 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 noon work for you?\r\n</body>\r\n</html>\r\n"
// },
// "start": {
// "dateTime": "2021-05-15T12:00:00.0000000",
// "timeZone": "Pacific Standard Time"
// },
// "end": {
// "dateTime": "2021-05-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": "Samantha Booth",
// "address": "samanthab@contoso.onmicrosoft.com"
// }
// }
// ],
// "organizer": {
// "emailAddress": {
// "name": "John Doe",
// "address": "outlook_3A33FCEB9B74CC15@outlook.com"
// }
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *displayName = 0;
const wchar_t *locationType = 0;
const wchar_t *uniqueId = 0;
const wchar_t *uniqueIdType = 0;
const wchar_t *statusResponse = 0;
const wchar_t *statusTime = 0;
const wchar_t *emailAddressName = 0;
const wchar_t *emailAddressAddress = 0;
const wchar_t *odata_context = jResp.stringOf(L"\"@odata.context\"");
const wchar_t *odata_etag = jResp.stringOf(L"\"@odata.etag\"");
const wchar_t *id = jResp.stringOf(L"id");
const wchar_t *createdDateTime = jResp.stringOf(L"createdDateTime");
const wchar_t *lastModifiedDateTime = jResp.stringOf(L"lastModifiedDateTime");
const wchar_t *changeKey = jResp.stringOf(L"changeKey");
const wchar_t *transactionId = jResp.stringOf(L"transactionId");
const wchar_t *originalStartTimeZone = jResp.stringOf(L"originalStartTimeZone");
const wchar_t *originalEndTimeZone = jResp.stringOf(L"originalEndTimeZone");
const wchar_t *iCalUId = jResp.stringOf(L"iCalUId");
int reminderMinutesBeforeStart = jResp.IntOf(L"reminderMinutesBeforeStart");
bool isReminderOn = jResp.BoolOf(L"isReminderOn");
bool hasAttachments = jResp.BoolOf(L"hasAttachments");
const wchar_t *subject = jResp.stringOf(L"subject");
const wchar_t *bodyPreview = jResp.stringOf(L"bodyPreview");
const wchar_t *importance = jResp.stringOf(L"importance");
const wchar_t *sensitivity = jResp.stringOf(L"sensitivity");
bool isAllDay = jResp.BoolOf(L"isAllDay");
bool isCancelled = jResp.BoolOf(L"isCancelled");
bool isOrganizer = jResp.BoolOf(L"isOrganizer");
bool responseRequested = jResp.BoolOf(L"responseRequested");
const wchar_t *seriesMasterId = jResp.stringOf(L"seriesMasterId");
const wchar_t *showAs = jResp.stringOf(L"showAs");
const wchar_t *v_type = jResp.stringOf(L"type");
const wchar_t *webLink = jResp.stringOf(L"webLink");
const wchar_t *onlineMeetingUrl = jResp.stringOf(L"onlineMeetingUrl");
bool isOnlineMeeting = jResp.BoolOf(L"isOnlineMeeting");
const wchar_t *onlineMeetingProvider = jResp.stringOf(L"onlineMeetingProvider");
bool allowNewTimeProposals = jResp.BoolOf(L"allowNewTimeProposals");
bool isDraft = jResp.BoolOf(L"isDraft");
bool hideAttendees = jResp.BoolOf(L"hideAttendees");
const wchar_t *recurrence = jResp.stringOf(L"recurrence");
const wchar_t *onlineMeeting = jResp.stringOf(L"onlineMeeting");
const wchar_t *responseStatusResponse = jResp.stringOf(L"responseStatus.response");
const wchar_t *responseStatusTime = jResp.stringOf(L"responseStatus.time");
const wchar_t *bodyContentType = jResp.stringOf(L"body.contentType");
const wchar_t *bodyContent = jResp.stringOf(L"body.content");
const wchar_t *startDateTime = jResp.stringOf(L"start.dateTime");
const wchar_t *startTimeZone = jResp.stringOf(L"start.timeZone");
const wchar_t *endDateTime = jResp.stringOf(L"end.dateTime");
const wchar_t *endTimeZone = jResp.stringOf(L"end.timeZone");
const wchar_t *locationDisplayName = jResp.stringOf(L"location.displayName");
const wchar_t *locationLocationType = jResp.stringOf(L"location.locationType");
const wchar_t *locationUniqueId = jResp.stringOf(L"location.uniqueId");
const wchar_t *locationUniqueIdType = jResp.stringOf(L"location.uniqueIdType");
const wchar_t *organizerEmailAddressName = jResp.stringOf(L"organizer.emailAddress.name");
const wchar_t *organizerEmailAddressAddress = jResp.stringOf(L"organizer.emailAddress.address");
int i = 0;
int count_i = jResp.SizeOfArray(L"categories");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"locations");
while (i < count_i) {
jResp.put_I(i);
displayName = jResp.stringOf(L"locations[i].displayName");
locationType = jResp.stringOf(L"locations[i].locationType");
uniqueId = jResp.stringOf(L"locations[i].uniqueId");
uniqueIdType = jResp.stringOf(L"locations[i].uniqueIdType");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"attendees");
while (i < count_i) {
jResp.put_I(i);
v_type = jResp.stringOf(L"attendees[i].type");
statusResponse = jResp.stringOf(L"attendees[i].status.response");
statusTime = jResp.stringOf(L"attendees[i].status.time");
emailAddressName = jResp.stringOf(L"attendees[i].emailAddress.name");
emailAddressAddress = jResp.stringOf(L"attendees[i].emailAddress.address");
i = i + 1;
}
wprintf(L"Event created.\n");
}