Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

; Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/outlookCalendar.json")
If ($bSuccess = False) Then
    ConsoleWrite($oJsonToken.LastErrorText & @CRLF)
    Exit
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 = ObjCreate("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",True)

; Generate a UUID.
$oCrypt = ObjCreate("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 = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://graph.microsoft.com/v1.0/me/events",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Response status code = " & $oResp.StatusCode & @CRLF)

$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.Load($oResp.BodyStr)
$oJResp.EmitCompact = False
ConsoleWrite($oJResp.Emit() & @CRLF)

; The send succeeded if the response status code = 201.
If ($oResp.StatusCode <> 201) Then
    ConsoleWrite("Failed" & @CRLF)
    Exit
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

Local $sDisplayName
Local $sLocationType
Local $sUniqueId
Local $sUniqueIdType
Local $statusResponse
Local $statusTime
Local $sEmailAddressName
Local $sEmailAddressAddress

Local $sOdata_context = $oJResp.StringOf("""@odata.context""")
Local $sOdata_etag = $oJResp.StringOf("""@odata.etag""")
Local $sId = $oJResp.StringOf("id")
Local $sCreatedDateTime = $oJResp.StringOf("createdDateTime")
Local $sLastModifiedDateTime = $oJResp.StringOf("lastModifiedDateTime")
Local $sChangeKey = $oJResp.StringOf("changeKey")
Local $sTransactionId = $oJResp.StringOf("transactionId")
Local $sOriginalStartTimeZone = $oJResp.StringOf("originalStartTimeZone")
Local $sOriginalEndTimeZone = $oJResp.StringOf("originalEndTimeZone")
Local $sICalUId = $oJResp.StringOf("iCalUId")
Local $iReminderMinutesBeforeStart = $oJResp.IntOf("reminderMinutesBeforeStart")
Local $bIsReminderOn = $oJResp.BoolOf("isReminderOn")
Local $bHasAttachments = $oJResp.BoolOf("hasAttachments")
Local $subject = $oJResp.StringOf("subject")
Local $sBodyPreview = $oJResp.StringOf("bodyPreview")
Local $sImportance = $oJResp.StringOf("importance")
Local $sensitivity = $oJResp.StringOf("sensitivity")
Local $bIsAllDay = $oJResp.BoolOf("isAllDay")
Local $bIsCancelled = $oJResp.BoolOf("isCancelled")
Local $bIsOrganizer = $oJResp.BoolOf("isOrganizer")
Local $bResponseRequested = $oJResp.BoolOf("responseRequested")
Local $seriesMasterId = $oJResp.StringOf("seriesMasterId")
Local $showAs = $oJResp.StringOf("showAs")
Local $sV_type = $oJResp.StringOf("type")
Local $sWebLink = $oJResp.StringOf("webLink")
Local $sOnlineMeetingUrl = $oJResp.StringOf("onlineMeetingUrl")
Local $bIsOnlineMeeting = $oJResp.BoolOf("isOnlineMeeting")
Local $sOnlineMeetingProvider = $oJResp.StringOf("onlineMeetingProvider")
Local $bAllowNewTimeProposals = $oJResp.BoolOf("allowNewTimeProposals")
Local $bIsDraft = $oJResp.BoolOf("isDraft")
Local $bHideAttendees = $oJResp.BoolOf("hideAttendees")
Local $sRecurrence = $oJResp.StringOf("recurrence")
Local $sOnlineMeeting = $oJResp.StringOf("onlineMeeting")
Local $sResponseStatusResponse = $oJResp.StringOf("responseStatus.response")
Local $sResponseStatusTime = $oJResp.StringOf("responseStatus.time")
Local $sBodyContentType = $oJResp.StringOf("body.contentType")
Local $sBodyContent = $oJResp.StringOf("body.content")
Local $startDateTime = $oJResp.StringOf("start.dateTime")
Local $startTimeZone = $oJResp.StringOf("start.timeZone")
Local $sEndDateTime = $oJResp.StringOf("end.dateTime")
Local $sEndTimeZone = $oJResp.StringOf("end.timeZone")
Local $sLocationDisplayName = $oJResp.StringOf("location.displayName")
Local $sLocationLocationType = $oJResp.StringOf("location.locationType")
Local $sLocationUniqueId = $oJResp.StringOf("location.uniqueId")
Local $sLocationUniqueIdType = $oJResp.StringOf("location.uniqueIdType")
Local $sOrganizerEmailAddressName = $oJResp.StringOf("organizer.emailAddress.name")
Local $sOrganizerEmailAddressAddress = $oJResp.StringOf("organizer.emailAddress.address")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("categories")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("locations")
While $i < $iCount_i
    $oJResp.I = $i
    $sDisplayName = $oJResp.StringOf("locations[i].displayName")
    $sLocationType = $oJResp.StringOf("locations[i].locationType")
    $sUniqueId = $oJResp.StringOf("locations[i].uniqueId")
    $sUniqueIdType = $oJResp.StringOf("locations[i].uniqueIdType")
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("attendees")
While $i < $iCount_i
    $oJResp.I = $i
    $sV_type = $oJResp.StringOf("attendees[i].type")
    $statusResponse = $oJResp.StringOf("attendees[i].status.response")
    $statusTime = $oJResp.StringOf("attendees[i].status.time")
    $sEmailAddressName = $oJResp.StringOf("attendees[i].emailAddress.name")
    $sEmailAddressAddress = $oJResp.StringOf("attendees[i].emailAddress.address")
    $i = $i + 1
Wend

ConsoleWrite("Event created." & @CRLF)