Sample code for 30+ languages & platforms
Visual FoxPro

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

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJsonToken
LOCAL loJson
LOCAL loCrypt
LOCAL loResp
LOCAL loJResp
LOCAL lcDisplayName
LOCAL lcLocationType
LOCAL lcUniqueId
LOCAL lcUniqueIdType
LOCAL lcStatusResponse
LOCAL lcStatusTime
LOCAL lcEmailAddressName
LOCAL lcEmailAddressAddress
LOCAL lcOdata_context
LOCAL lcOdata_etag
LOCAL lcId
LOCAL lcCreatedDateTime
LOCAL lcLastModifiedDateTime
LOCAL lcChangeKey
LOCAL lcTransactionId
LOCAL lcOriginalStartTimeZone
LOCAL lcOriginalEndTimeZone
LOCAL lcICalUId
LOCAL lnReminderMinutesBeforeStart
LOCAL lnIsReminderOn
LOCAL lnHasAttachments
LOCAL lcSubject
LOCAL lcBodyPreview
LOCAL lcImportance
LOCAL lcSensitivity
LOCAL lnIsAllDay
LOCAL lnIsCancelled
LOCAL lnIsOrganizer
LOCAL lnResponseRequested
LOCAL lcSeriesMasterId
LOCAL lcShowAs
LOCAL lcV_type
LOCAL lcWebLink
LOCAL lcOnlineMeetingUrl
LOCAL lnIsOnlineMeeting
LOCAL lcOnlineMeetingProvider
LOCAL lnAllowNewTimeProposals
LOCAL lnIsDraft
LOCAL lnHideAttendees
LOCAL lcRecurrence
LOCAL lcOnlineMeeting
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 here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

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

loHttp.AuthToken = loJsonToken.StringOf("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.
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("subject","Let's go for lunch")
loJson.UpdateString("body.contentType","HTML")
loJson.UpdateString("body.content","Does noon work for you?")
loJson.UpdateString("start.dateTime","2021-05-15T12:00:00")
loJson.UpdateString("start.timeZone","Pacific Standard Time")
loJson.UpdateString("end.dateTime","2021-05-15T14:00:00")
loJson.UpdateString("end.timeZone","Pacific Standard Time")
loJson.UpdateString("location.displayName","Harry's Bar")
loJson.UpdateString("attendees[0].emailAddress.address","samanthab@contoso.onmicrosoft.com")
loJson.UpdateString("attendees[0].emailAddress.name","Samantha Booth")
loJson.UpdateString("attendees[0].type","required")
loJson.UpdateBool("allowNewTimeProposals",1)

* Generate a UUID.
loCrypt = CreateObject('Chilkat.Crypt2')
loJson.UpdateString("transactionId",loCrypt.GenerateUuid())

* Add the "Prefer" request header.
loHttp.SetRequestHeader("Prefer",'outlook.timezone="Pacific Standard Time"')

* Send the HTTP POST
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://graph.microsoft.com/v1.0/me/events",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    RELEASE loCrypt
    RELEASE loResp
    CANCEL
ENDIF

? "Response status code = " + STR(loResp.StatusCode)

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.Load(loResp.BodyStr)
loJResp.EmitCompact = 0
? loJResp.Emit()

* The send succeeded if the response status code = 201.
IF (loResp.StatusCode <> 201) THEN
    ? "Failed"
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    RELEASE loCrypt
    RELEASE loResp
    RELEASE loJResp
    CANCEL
ENDIF

* 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

lcOdata_context = loJResp.StringOf('"@odata.context"')
lcOdata_etag = loJResp.StringOf('"@odata.etag"')
lcId = loJResp.StringOf("id")
lcCreatedDateTime = loJResp.StringOf("createdDateTime")
lcLastModifiedDateTime = loJResp.StringOf("lastModifiedDateTime")
lcChangeKey = loJResp.StringOf("changeKey")
lcTransactionId = loJResp.StringOf("transactionId")
lcOriginalStartTimeZone = loJResp.StringOf("originalStartTimeZone")
lcOriginalEndTimeZone = loJResp.StringOf("originalEndTimeZone")
lcICalUId = loJResp.StringOf("iCalUId")
lnReminderMinutesBeforeStart = loJResp.IntOf("reminderMinutesBeforeStart")
lnIsReminderOn = loJResp.BoolOf("isReminderOn")
lnHasAttachments = loJResp.BoolOf("hasAttachments")
lcSubject = loJResp.StringOf("subject")
lcBodyPreview = loJResp.StringOf("bodyPreview")
lcImportance = loJResp.StringOf("importance")
lcSensitivity = loJResp.StringOf("sensitivity")
lnIsAllDay = loJResp.BoolOf("isAllDay")
lnIsCancelled = loJResp.BoolOf("isCancelled")
lnIsOrganizer = loJResp.BoolOf("isOrganizer")
lnResponseRequested = loJResp.BoolOf("responseRequested")
lcSeriesMasterId = loJResp.StringOf("seriesMasterId")
lcShowAs = loJResp.StringOf("showAs")
lcV_type = loJResp.StringOf("type")
lcWebLink = loJResp.StringOf("webLink")
lcOnlineMeetingUrl = loJResp.StringOf("onlineMeetingUrl")
lnIsOnlineMeeting = loJResp.BoolOf("isOnlineMeeting")
lcOnlineMeetingProvider = loJResp.StringOf("onlineMeetingProvider")
lnAllowNewTimeProposals = loJResp.BoolOf("allowNewTimeProposals")
lnIsDraft = loJResp.BoolOf("isDraft")
lnHideAttendees = loJResp.BoolOf("hideAttendees")
lcRecurrence = loJResp.StringOf("recurrence")
lcOnlineMeeting = loJResp.StringOf("onlineMeeting")
lcResponseStatusResponse = loJResp.StringOf("responseStatus.response")
lcResponseStatusTime = loJResp.StringOf("responseStatus.time")
lcBodyContentType = loJResp.StringOf("body.contentType")
lcBodyContent = loJResp.StringOf("body.content")
lcStartDateTime = loJResp.StringOf("start.dateTime")
lcStartTimeZone = loJResp.StringOf("start.timeZone")
lcEndDateTime = loJResp.StringOf("end.dateTime")
lcEndTimeZone = loJResp.StringOf("end.timeZone")
lcLocationDisplayName = loJResp.StringOf("location.displayName")
lcLocationLocationType = loJResp.StringOf("location.locationType")
lcLocationUniqueId = loJResp.StringOf("location.uniqueId")
lcLocationUniqueIdType = loJResp.StringOf("location.uniqueIdType")
lcOrganizerEmailAddressName = loJResp.StringOf("organizer.emailAddress.name")
lcOrganizerEmailAddressAddress = loJResp.StringOf("organizer.emailAddress.address")
i = 0
lnCount_i = loJResp.SizeOfArray("categories")
DO WHILE i < lnCount_i
    loJResp.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("locations")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcDisplayName = loJResp.StringOf("locations[i].displayName")
    lcLocationType = loJResp.StringOf("locations[i].locationType")
    lcUniqueId = loJResp.StringOf("locations[i].uniqueId")
    lcUniqueIdType = loJResp.StringOf("locations[i].uniqueIdType")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("attendees")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcV_type = loJResp.StringOf("attendees[i].type")
    lcStatusResponse = loJResp.StringOf("attendees[i].status.response")
    lcStatusTime = loJResp.StringOf("attendees[i].status.time")
    lcEmailAddressName = loJResp.StringOf("attendees[i].emailAddress.name")
    lcEmailAddressAddress = loJResp.StringOf("attendees[i].emailAddress.address")
    i = i + 1
ENDDO

? "Event created."

RELEASE loHttp
RELEASE loJsonToken
RELEASE loJson
RELEASE loCrypt
RELEASE loResp
RELEASE loJResp