Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oJson
LOCAL oCrypt
LOCAL oResp
LOCAL oJResp
LOCAL cDisplayName
LOCAL cLocationType
LOCAL cUniqueId
LOCAL cUniqueIdType
LOCAL cStatusResponse
LOCAL cStatusTime
LOCAL cEmailAddressName
LOCAL cEmailAddressAddress
LOCAL cOdata_context
LOCAL cOdata_etag
LOCAL cId
LOCAL cCreatedDateTime
LOCAL cLastModifiedDateTime
LOCAL cChangeKey
LOCAL cTransactionId
LOCAL cOriginalStartTimeZone
LOCAL cOriginalEndTimeZone
LOCAL cICalUId
LOCAL nReminderMinutesBeforeStart
LOCAL nIsReminderOn
LOCAL nHasAttachments
LOCAL cSubject
LOCAL cBodyPreview
LOCAL cImportance
LOCAL cSensitivity
LOCAL nIsAllDay
LOCAL nIsCancelled
LOCAL nIsOrganizer
LOCAL nResponseRequested
LOCAL cSeriesMasterId
LOCAL cShowAs
LOCAL cV_type
LOCAL cWebLink
LOCAL cOnlineMeetingUrl
LOCAL nIsOnlineMeeting
LOCAL cOnlineMeetingProvider
LOCAL nAllowNewTimeProposals
LOCAL nIsDraft
LOCAL nHideAttendees
LOCAL cRecurrence
LOCAL cOnlineMeeting
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 here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/outlookCalendar.json")
IF (nSuccess == 0)
    ? oJsonToken:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    RETURN
ENDIF

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

//  Generate a UUID.
oCrypt := CreateObject("Chilkat.Crypt2")
oJson:UpdateString("transactionId", oCrypt:GenerateUuid())

//  Add the "Prefer" request header.
oHttp:SetRequestHeader("Prefer", 'outlook.timezone="Pacific Standard Time"')

//  Send the HTTP POST
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://graph.microsoft.com/v1.0/me/events", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJsonToken:destroy()
    oJson:destroy()
    oCrypt:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response status code = " + Str(oResp:StatusCode)

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:Load(oResp:BodyStr)
oJResp:EmitCompact := 0
? oJResp:Emit()

//  The send succeeded if the response status code = 201.
IF (oResp:StatusCode != 201)
    ? "Failed"
    oHttp:destroy()
    oJsonToken:destroy()
    oJson:destroy()
    oCrypt:destroy()
    oResp:destroy()
    oJResp:destroy()
    RETURN
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

cOdata_context := oJResp:StringOf('"@odata.context"')
cOdata_etag := oJResp:StringOf('"@odata.etag"')
cId := oJResp:StringOf("id")
cCreatedDateTime := oJResp:StringOf("createdDateTime")
cLastModifiedDateTime := oJResp:StringOf("lastModifiedDateTime")
cChangeKey := oJResp:StringOf("changeKey")
cTransactionId := oJResp:StringOf("transactionId")
cOriginalStartTimeZone := oJResp:StringOf("originalStartTimeZone")
cOriginalEndTimeZone := oJResp:StringOf("originalEndTimeZone")
cICalUId := oJResp:StringOf("iCalUId")
nReminderMinutesBeforeStart := oJResp:IntOf("reminderMinutesBeforeStart")
nIsReminderOn := oJResp:BoolOf("isReminderOn")
nHasAttachments := oJResp:BoolOf("hasAttachments")
cSubject := oJResp:StringOf("subject")
cBodyPreview := oJResp:StringOf("bodyPreview")
cImportance := oJResp:StringOf("importance")
cSensitivity := oJResp:StringOf("sensitivity")
nIsAllDay := oJResp:BoolOf("isAllDay")
nIsCancelled := oJResp:BoolOf("isCancelled")
nIsOrganizer := oJResp:BoolOf("isOrganizer")
nResponseRequested := oJResp:BoolOf("responseRequested")
cSeriesMasterId := oJResp:StringOf("seriesMasterId")
cShowAs := oJResp:StringOf("showAs")
cV_type := oJResp:StringOf("type")
cWebLink := oJResp:StringOf("webLink")
cOnlineMeetingUrl := oJResp:StringOf("onlineMeetingUrl")
nIsOnlineMeeting := oJResp:BoolOf("isOnlineMeeting")
cOnlineMeetingProvider := oJResp:StringOf("onlineMeetingProvider")
nAllowNewTimeProposals := oJResp:BoolOf("allowNewTimeProposals")
nIsDraft := oJResp:BoolOf("isDraft")
nHideAttendees := oJResp:BoolOf("hideAttendees")
cRecurrence := oJResp:StringOf("recurrence")
cOnlineMeeting := oJResp:StringOf("onlineMeeting")
cResponseStatusResponse := oJResp:StringOf("responseStatus.response")
cResponseStatusTime := oJResp:StringOf("responseStatus.time")
cBodyContentType := oJResp:StringOf("body.contentType")
cBodyContent := oJResp:StringOf("body.content")
cStartDateTime := oJResp:StringOf("start.dateTime")
cStartTimeZone := oJResp:StringOf("start.timeZone")
cEndDateTime := oJResp:StringOf("end.dateTime")
cEndTimeZone := oJResp:StringOf("end.timeZone")
cLocationDisplayName := oJResp:StringOf("location.displayName")
cLocationLocationType := oJResp:StringOf("location.locationType")
cLocationUniqueId := oJResp:StringOf("location.uniqueId")
cLocationUniqueIdType := oJResp:StringOf("location.uniqueIdType")
cOrganizerEmailAddressName := oJResp:StringOf("organizer.emailAddress.name")
cOrganizerEmailAddressAddress := oJResp:StringOf("organizer.emailAddress.address")
i := 0
nCount_i := oJResp:SizeOfArray("categories")
DO WHILE i < nCount_i
    oJResp:I := i
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("locations")
DO WHILE i < nCount_i
    oJResp:I := i
    cDisplayName := oJResp:StringOf("locations[i].displayName")
    cLocationType := oJResp:StringOf("locations[i].locationType")
    cUniqueId := oJResp:StringOf("locations[i].uniqueId")
    cUniqueIdType := oJResp:StringOf("locations[i].uniqueIdType")
    i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("attendees")
DO WHILE i < nCount_i
    oJResp:I := i
    cV_type := oJResp:StringOf("attendees[i].type")
    cStatusResponse := oJResp:StringOf("attendees[i].status.response")
    cStatusTime := oJResp:StringOf("attendees[i].status.time")
    cEmailAddressName := oJResp:StringOf("attendees[i].emailAddress.name")
    cEmailAddressAddress := oJResp:StringOf("attendees[i].emailAddress.address")
    i := i + 1
ENDDO

? "Event created."

oHttp:destroy()
oJsonToken:destroy()
oJson:destroy()
oCrypt:destroy()
oResp:destroy()
oJResp:destroy()