Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oJson
LOCAL oResp
LOCAL cDisplayName
LOCAL cLocationType
LOCAL cUniqueId
LOCAL cUniqueIdType
LOCAL cStatusResponse
LOCAL cStatusTime
LOCAL cEmailAddressName
LOCAL cEmailAddressAddress
LOCAL cOdataContext
LOCAL cOdataEtag
LOCAL cId
LOCAL cCreatedDateTime
LOCAL cLastModifiedDateTime
LOCAL cChangeKey
LOCAL cOriginalStartTimeZone
LOCAL cOriginalEndTimeZone
LOCAL cICalUId
LOCAL cReminderMinutesBeforeStart
LOCAL cIsReminderOn
LOCAL cHasAttachments
LOCAL cSubject
LOCAL cBodyPreview
LOCAL cImportance
LOCAL cSensitivity
LOCAL cIsAllDay
LOCAL cIsCancelled
LOCAL cIsOrganizer
LOCAL cResponseRequested
LOCAL cSeriesMasterId
LOCAL cShowAs
LOCAL cType
LOCAL cWebLink
LOCAL cOnlineMeetingUrl
LOCAL cRecurrence
LOCAL cResponseStatusResponse
LOCAL cResponseStatusTime
LOCAL cBodyContentType
LOCAL cBodyContent
LOCAL cStartDateTime
LOCAL cStartTimeZone
LOCAL cEndDateTime
LOCAL cEndTimeZone
LOCAL cLocationDisplayName
LOCAL cLocationLocationType
LOCAL cLocationUniqueId
LOCAL cLocationUniqueIdType
LOCAL cOrganizerEmailAddressName
LOCAL cOrganizerEmailAddressAddress
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/msGraphCalendar.json")
IF (nSuccess == 0)
? oJsonToken:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
RETURN
ENDIF
oHttp:AuthToken := oJsonToken:StringOf("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"
// }
// ]
// }
oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("subject", "Let's go for lunch")
oJson:UpdateString("body.contentType", "HTML")
oJson:UpdateString("body.content", "Does mid month work for you?")
oJson:UpdateString("start.dateTime", "2019-11-15T12:00:00")
oJson:UpdateString("start.timeZone", "Pacific Standard Time")
oJson:UpdateString("end.dateTime", "2019-11-15T14:00:00")
oJson:UpdateString("end.timeZone", "Pacific Standard Time")
oJson:UpdateString("location.displayName", "Harry's Bar")
oJson:UpdateString("attendees[0].emailAddress.address", "adelev@contoso.onmicrosoft.com")
oJson:UpdateString("attendees[0].emailAddress.name", "Adele Vance")
oJson:UpdateString("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
oHttp:SetUrlVar("id", "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
oJson:Load(oResp:BodyStr)
oJson:EmitCompact := 0
IF (oResp:StatusCode != 201)
? oJson:Emit()
? "Failed, response status code = " + Str(oResp:StatusCode)
oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
? oJson:Emit()
// 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
cOdataContext := oJson:StringOf('"@odata.context"')
cOdataEtag := oJson:StringOf('"@odata.etag"')
cId := oJson:StringOf("id")
cCreatedDateTime := oJson:StringOf("createdDateTime")
cLastModifiedDateTime := oJson:StringOf("lastModifiedDateTime")
cChangeKey := oJson:StringOf("changeKey")
cOriginalStartTimeZone := oJson:StringOf("originalStartTimeZone")
cOriginalEndTimeZone := oJson:StringOf("originalEndTimeZone")
cICalUId := oJson:StringOf("iCalUId")
cReminderMinutesBeforeStart := oJson:IntOf("reminderMinutesBeforeStart")
cIsReminderOn := oJson:BoolOf("isReminderOn")
cHasAttachments := oJson:BoolOf("hasAttachments")
cSubject := oJson:StringOf("subject")
cBodyPreview := oJson:StringOf("bodyPreview")
cImportance := oJson:StringOf("importance")
cSensitivity := oJson:StringOf("sensitivity")
cIsAllDay := oJson:BoolOf("isAllDay")
cIsCancelled := oJson:BoolOf("isCancelled")
cIsOrganizer := oJson:BoolOf("isOrganizer")
cResponseRequested := oJson:BoolOf("responseRequested")
cSeriesMasterId := oJson:StringOf("seriesMasterId")
cShowAs := oJson:StringOf("showAs")
cType := oJson:StringOf("type")
cWebLink := oJson:StringOf("webLink")
cOnlineMeetingUrl := oJson:StringOf("onlineMeetingUrl")
cRecurrence := oJson:StringOf("recurrence")
cResponseStatusResponse := oJson:StringOf("responseStatus.response")
cResponseStatusTime := oJson:StringOf("responseStatus.time")
cBodyContentType := oJson:StringOf("body.contentType")
cBodyContent := oJson:StringOf("body.content")
cStartDateTime := oJson:StringOf("start.dateTime")
cStartTimeZone := oJson:StringOf("start.timeZone")
cEndDateTime := oJson:StringOf("end.dateTime")
cEndTimeZone := oJson:StringOf("end.timeZone")
cLocationDisplayName := oJson:StringOf("location.displayName")
cLocationLocationType := oJson:StringOf("location.locationType")
cLocationUniqueId := oJson:StringOf("location.uniqueId")
cLocationUniqueIdType := oJson:StringOf("location.uniqueIdType")
cOrganizerEmailAddressName := oJson:StringOf("organizer.emailAddress.name")
cOrganizerEmailAddressAddress := oJson:StringOf("organizer.emailAddress.address")
i := 0
nCount_i := oJson:SizeOfArray("categories")
DO WHILE i < nCount_i
oJson:I := i
// ...
i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("locations")
DO WHILE i < nCount_i
oJson:I := i
cDisplayName := oJson:StringOf("locations[i].displayName")
cLocationType := oJson:StringOf("locations[i].locationType")
cUniqueId := oJson:StringOf("locations[i].uniqueId")
cUniqueIdType := oJson:StringOf("locations[i].uniqueIdType")
i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("attendees")
DO WHILE i < nCount_i
oJson:I := i
cType := oJson:StringOf("attendees[i].type")
cStatusResponse := oJson:StringOf("attendees[i].status.response")
cStatusTime := oJson:StringOf("attendees[i].status.time")
cEmailAddressName := oJson:StringOf("attendees[i].emailAddress.name")
cEmailAddressAddress := oJson:StringOf("attendees[i].emailAddress.address")
i := i + 1
ENDDO
? "Success."
oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
oResp:destroy()