Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW jsonToken;
HCkJsonObjectW json;
HCkHttpResponseW resp;
const wchar_t *displayName;
const wchar_t *locationType;
const wchar_t *uniqueId;
const wchar_t *uniqueIdType;
const wchar_t *statusResponse;
const wchar_t *statusTime;
const wchar_t *emailAddressName;
const wchar_t *emailAddressAddress;
const wchar_t *odataContext;
const wchar_t *odataEtag;
const wchar_t *id;
const wchar_t *createdDateTime;
const wchar_t *lastModifiedDateTime;
const wchar_t *changeKey;
const wchar_t *originalStartTimeZone;
const wchar_t *originalEndTimeZone;
const wchar_t *iCalUId;
const wchar_t *reminderMinutesBeforeStart;
const wchar_t *isReminderOn;
const wchar_t *hasAttachments;
const wchar_t *subject;
const wchar_t *bodyPreview;
const wchar_t *importance;
const wchar_t *sensitivity;
const wchar_t *isAllDay;
const wchar_t *isCancelled;
const wchar_t *isOrganizer;
const wchar_t *responseRequested;
const wchar_t *seriesMasterId;
const wchar_t *showAs;
const wchar_t *type;
const wchar_t *webLink;
const wchar_t *onlineMeetingUrl;
const wchar_t *recurrence;
const wchar_t *responseStatusResponse;
const wchar_t *responseStatusTime;
const wchar_t *bodyContentType;
const wchar_t *bodyContent;
const wchar_t *startDateTime;
const wchar_t *startTimeZone;
const wchar_t *endDateTime;
const wchar_t *endTimeZone;
const wchar_t *locationDisplayName;
const wchar_t *locationLocationType;
const wchar_t *locationUniqueId;
const wchar_t *locationUniqueIdType;
const wchar_t *organizerEmailAddressName;
const wchar_t *organizerEmailAddressAddress;
int i;
int count_i;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
jsonToken = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/msGraphCalendar.json");
if (success == FALSE) {
wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
return;
}
CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));
// 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"
// }
// ]
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"subject",L"Let's go for lunch");
CkJsonObjectW_UpdateString(json,L"body.contentType",L"HTML");
CkJsonObjectW_UpdateString(json,L"body.content",L"Does mid month work for you?");
CkJsonObjectW_UpdateString(json,L"start.dateTime",L"2019-11-15T12:00:00");
CkJsonObjectW_UpdateString(json,L"start.timeZone",L"Pacific Standard Time");
CkJsonObjectW_UpdateString(json,L"end.dateTime",L"2019-11-15T14:00:00");
CkJsonObjectW_UpdateString(json,L"end.timeZone",L"Pacific Standard Time");
CkJsonObjectW_UpdateString(json,L"location.displayName",L"Harry's Bar");
CkJsonObjectW_UpdateString(json,L"attendees[0].emailAddress.address",L"adelev@contoso.onmicrosoft.com");
CkJsonObjectW_UpdateString(json,L"attendees[0].emailAddress.name",L"Adele Vance");
CkJsonObjectW_UpdateString(json,L"attendees[0].type",L"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
CkHttpW_SetUrlVar(http,L"id",L"AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==");
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpJson(http,L"POST",L"https://graph.microsoft.com/v1.0/me/calendars/{$id}/events",json,L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp));
CkJsonObjectW_putEmitCompact(json,FALSE);
if (CkHttpResponseW_getStatusCode(resp) != 201) {
wprintf(L"%s\n",CkJsonObjectW_emit(json));
wprintf(L"Failed, response status code = %d\n",CkHttpResponseW_getStatusCode(resp));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"%s\n",CkJsonObjectW_emit(json));
// 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
odataContext = CkJsonObjectW_stringOf(json,L"\"@odata.context\"");
odataEtag = CkJsonObjectW_stringOf(json,L"\"@odata.etag\"");
id = CkJsonObjectW_stringOf(json,L"id");
createdDateTime = CkJsonObjectW_stringOf(json,L"createdDateTime");
lastModifiedDateTime = CkJsonObjectW_stringOf(json,L"lastModifiedDateTime");
changeKey = CkJsonObjectW_stringOf(json,L"changeKey");
originalStartTimeZone = CkJsonObjectW_stringOf(json,L"originalStartTimeZone");
originalEndTimeZone = CkJsonObjectW_stringOf(json,L"originalEndTimeZone");
iCalUId = CkJsonObjectW_stringOf(json,L"iCalUId");
reminderMinutesBeforeStart = CkJsonObjectW_IntOf(json,L"reminderMinutesBeforeStart");
isReminderOn = CkJsonObjectW_BoolOf(json,L"isReminderOn");
hasAttachments = CkJsonObjectW_BoolOf(json,L"hasAttachments");
subject = CkJsonObjectW_stringOf(json,L"subject");
bodyPreview = CkJsonObjectW_stringOf(json,L"bodyPreview");
importance = CkJsonObjectW_stringOf(json,L"importance");
sensitivity = CkJsonObjectW_stringOf(json,L"sensitivity");
isAllDay = CkJsonObjectW_BoolOf(json,L"isAllDay");
isCancelled = CkJsonObjectW_BoolOf(json,L"isCancelled");
isOrganizer = CkJsonObjectW_BoolOf(json,L"isOrganizer");
responseRequested = CkJsonObjectW_BoolOf(json,L"responseRequested");
seriesMasterId = CkJsonObjectW_stringOf(json,L"seriesMasterId");
showAs = CkJsonObjectW_stringOf(json,L"showAs");
type = CkJsonObjectW_stringOf(json,L"type");
webLink = CkJsonObjectW_stringOf(json,L"webLink");
onlineMeetingUrl = CkJsonObjectW_stringOf(json,L"onlineMeetingUrl");
recurrence = CkJsonObjectW_stringOf(json,L"recurrence");
responseStatusResponse = CkJsonObjectW_stringOf(json,L"responseStatus.response");
responseStatusTime = CkJsonObjectW_stringOf(json,L"responseStatus.time");
bodyContentType = CkJsonObjectW_stringOf(json,L"body.contentType");
bodyContent = CkJsonObjectW_stringOf(json,L"body.content");
startDateTime = CkJsonObjectW_stringOf(json,L"start.dateTime");
startTimeZone = CkJsonObjectW_stringOf(json,L"start.timeZone");
endDateTime = CkJsonObjectW_stringOf(json,L"end.dateTime");
endTimeZone = CkJsonObjectW_stringOf(json,L"end.timeZone");
locationDisplayName = CkJsonObjectW_stringOf(json,L"location.displayName");
locationLocationType = CkJsonObjectW_stringOf(json,L"location.locationType");
locationUniqueId = CkJsonObjectW_stringOf(json,L"location.uniqueId");
locationUniqueIdType = CkJsonObjectW_stringOf(json,L"location.uniqueIdType");
organizerEmailAddressName = CkJsonObjectW_stringOf(json,L"organizer.emailAddress.name");
organizerEmailAddressAddress = CkJsonObjectW_stringOf(json,L"organizer.emailAddress.address");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"categories");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
// ...
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"locations");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
displayName = CkJsonObjectW_stringOf(json,L"locations[i].displayName");
locationType = CkJsonObjectW_stringOf(json,L"locations[i].locationType");
uniqueId = CkJsonObjectW_stringOf(json,L"locations[i].uniqueId");
uniqueIdType = CkJsonObjectW_stringOf(json,L"locations[i].uniqueIdType");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"attendees");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
type = CkJsonObjectW_stringOf(json,L"attendees[i].type");
statusResponse = CkJsonObjectW_stringOf(json,L"attendees[i].status.response");
statusTime = CkJsonObjectW_stringOf(json,L"attendees[i].status.time");
emailAddressName = CkJsonObjectW_stringOf(json,L"attendees[i].emailAddress.name");
emailAddressAddress = CkJsonObjectW_stringOf(json,L"attendees[i].emailAddress.address");
i = i + 1;
}
wprintf(L"Success.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
}