Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJsonToken
LOCAL loJson
LOCAL loResp
LOCAL lcDisplayName
LOCAL lcLocationType
LOCAL lcUniqueId
LOCAL lcUniqueIdType
LOCAL lcStatusResponse
LOCAL lcStatusTime
LOCAL lcEmailAddressName
LOCAL lcEmailAddressAddress
LOCAL lcOdataContext
LOCAL lcOdataEtag
LOCAL lcId
LOCAL lcCreatedDateTime
LOCAL lcLastModifiedDateTime
LOCAL lcChangeKey
LOCAL lcOriginalStartTimeZone
LOCAL lcOriginalEndTimeZone
LOCAL lcICalUId
LOCAL lcReminderMinutesBeforeStart
LOCAL lcIsReminderOn
LOCAL lcHasAttachments
LOCAL lcSubject
LOCAL lcBodyPreview
LOCAL lcImportance
LOCAL lcSensitivity
LOCAL lcIsAllDay
LOCAL lcIsCancelled
LOCAL lcIsOrganizer
LOCAL lcResponseRequested
LOCAL lcSeriesMasterId
LOCAL lcShowAs
LOCAL lcType
LOCAL lcWebLink
LOCAL lcOnlineMeetingUrl
LOCAL lcRecurrence
LOCAL lcResponseStatusResponse
LOCAL lcResponseStatusTime
LOCAL lcBodyContentType
LOCAL lcBodyContent
LOCAL lcStartDateTime
LOCAL lcStartTimeZone
LOCAL lcEndDateTime
LOCAL lcEndTimeZone
LOCAL lcLocationDisplayName
LOCAL lcLocationLocationType
LOCAL lcLocationUniqueId
LOCAL lcLocationUniqueIdType
LOCAL lcOrganizerEmailAddressName
LOCAL lcOrganizerEmailAddressAddress
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat.Http')

* Use your previously obtained access token as shown here:
*    Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.

loJsonToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loJsonToken.LoadFile("qa_data/tokens/msGraphCalendar.json")
IF (lnSuccess = 0) THEN
    ? loJsonToken.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    CANCEL
ENDIF

loHttp.AuthToken = loJsonToken.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"
*     }
*   ]
* }

loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("subject","Let's go for lunch")
loJson.UpdateString("body.contentType","HTML")
loJson.UpdateString("body.content","Does mid month work for you?")
loJson.UpdateString("start.dateTime","2019-11-15T12:00:00")
loJson.UpdateString("start.timeZone","Pacific Standard Time")
loJson.UpdateString("end.dateTime","2019-11-15T14:00:00")
loJson.UpdateString("end.timeZone","Pacific Standard Time")
loJson.UpdateString("location.displayName","Harry's Bar")
loJson.UpdateString("attendees[0].emailAddress.address","adelev@contoso.onmicrosoft.com")
loJson.UpdateString("attendees[0].emailAddress.name","Adele Vance")
loJson.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
loHttp.SetUrlVar("id","AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://graph.microsoft.com/v1.0/me/calendars/{$id}/events",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    RELEASE loResp
    CANCEL
ENDIF

loJson.Load(loResp.BodyStr)
loJson.EmitCompact = 0

IF (loResp.StatusCode <> 201) THEN
    ? loJson.Emit()
    ? "Failed, response status code = " + STR(loResp.StatusCode)
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    RELEASE loResp
    CANCEL
ENDIF

? loJson.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

lcOdataContext = loJson.StringOf('"@odata.context"')
lcOdataEtag = loJson.StringOf('"@odata.etag"')
lcId = loJson.StringOf("id")
lcCreatedDateTime = loJson.StringOf("createdDateTime")
lcLastModifiedDateTime = loJson.StringOf("lastModifiedDateTime")
lcChangeKey = loJson.StringOf("changeKey")
lcOriginalStartTimeZone = loJson.StringOf("originalStartTimeZone")
lcOriginalEndTimeZone = loJson.StringOf("originalEndTimeZone")
lcICalUId = loJson.StringOf("iCalUId")
lcReminderMinutesBeforeStart = loJson.IntOf("reminderMinutesBeforeStart")
lcIsReminderOn = loJson.BoolOf("isReminderOn")
lcHasAttachments = loJson.BoolOf("hasAttachments")
lcSubject = loJson.StringOf("subject")
lcBodyPreview = loJson.StringOf("bodyPreview")
lcImportance = loJson.StringOf("importance")
lcSensitivity = loJson.StringOf("sensitivity")
lcIsAllDay = loJson.BoolOf("isAllDay")
lcIsCancelled = loJson.BoolOf("isCancelled")
lcIsOrganizer = loJson.BoolOf("isOrganizer")
lcResponseRequested = loJson.BoolOf("responseRequested")
lcSeriesMasterId = loJson.StringOf("seriesMasterId")
lcShowAs = loJson.StringOf("showAs")
lcType = loJson.StringOf("type")
lcWebLink = loJson.StringOf("webLink")
lcOnlineMeetingUrl = loJson.StringOf("onlineMeetingUrl")
lcRecurrence = loJson.StringOf("recurrence")
lcResponseStatusResponse = loJson.StringOf("responseStatus.response")
lcResponseStatusTime = loJson.StringOf("responseStatus.time")
lcBodyContentType = loJson.StringOf("body.contentType")
lcBodyContent = loJson.StringOf("body.content")
lcStartDateTime = loJson.StringOf("start.dateTime")
lcStartTimeZone = loJson.StringOf("start.timeZone")
lcEndDateTime = loJson.StringOf("end.dateTime")
lcEndTimeZone = loJson.StringOf("end.timeZone")
lcLocationDisplayName = loJson.StringOf("location.displayName")
lcLocationLocationType = loJson.StringOf("location.locationType")
lcLocationUniqueId = loJson.StringOf("location.uniqueId")
lcLocationUniqueIdType = loJson.StringOf("location.uniqueIdType")
lcOrganizerEmailAddressName = loJson.StringOf("organizer.emailAddress.name")
lcOrganizerEmailAddressAddress = loJson.StringOf("organizer.emailAddress.address")
i = 0
lnCount_i = loJson.SizeOfArray("categories")
DO WHILE i < lnCount_i
    loJson.I = i
    * ...
    i = i + 1
ENDDO
i = 0
lnCount_i = loJson.SizeOfArray("locations")
DO WHILE i < lnCount_i
    loJson.I = i
    lcDisplayName = loJson.StringOf("locations[i].displayName")
    lcLocationType = loJson.StringOf("locations[i].locationType")
    lcUniqueId = loJson.StringOf("locations[i].uniqueId")
    lcUniqueIdType = loJson.StringOf("locations[i].uniqueIdType")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJson.SizeOfArray("attendees")
DO WHILE i < lnCount_i
    loJson.I = i
    lcType = loJson.StringOf("attendees[i].type")
    lcStatusResponse = loJson.StringOf("attendees[i].status.response")
    lcStatusTime = loJson.StringOf("attendees[i].status.time")
    lcEmailAddressName = loJson.StringOf("attendees[i].emailAddress.name")
    lcEmailAddressAddress = loJson.StringOf("attendees[i].emailAddress.address")
    i = i + 1
ENDDO

? "Success."

RELEASE loHttp
RELEASE loJsonToken
RELEASE loJson
RELEASE loResp