Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Outlook Calendar Create an EventSee more Outlook Calendar ExamplesCreate an event in the specified time zone, and assign the event an optional transactionId value. For more information, see https://docs.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http#example-1-create-an-event-in-the-specified-time-zone-and-assign-the-event-an-optional-transactionid-value
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkCrypt2.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint). jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/outlookCalendar.json") If success = 0 Debug CkJsonObject::ckLastErrorText(jsonToken) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) ProcedureReturn EndIf CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"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. json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"subject","Let's go for lunch") CkJsonObject::ckUpdateString(json,"body.contentType","HTML") CkJsonObject::ckUpdateString(json,"body.content","Does noon work for you?") CkJsonObject::ckUpdateString(json,"start.dateTime","2021-05-15T12:00:00") CkJsonObject::ckUpdateString(json,"start.timeZone","Pacific Standard Time") CkJsonObject::ckUpdateString(json,"end.dateTime","2021-05-15T14:00:00") CkJsonObject::ckUpdateString(json,"end.timeZone","Pacific Standard Time") CkJsonObject::ckUpdateString(json,"location.displayName","Harry's Bar") CkJsonObject::ckUpdateString(json,"attendees[0].emailAddress.address","samanthab@contoso.onmicrosoft.com") CkJsonObject::ckUpdateString(json,"attendees[0].emailAddress.name","Samantha Booth") CkJsonObject::ckUpdateString(json,"attendees[0].type","required") CkJsonObject::ckUpdateBool(json,"allowNewTimeProposals",1) ; Generate a UUID. crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"transactionId",CkCrypt2::ckGenerateUuid(crypt)) ; Add the "Prefer" request header. CkHttp::ckSetRequestHeader(http,"Prefer","outlook.timezone=" + Chr(34) + "Pacific Standard Time" + Chr(34)) ; Send the HTTP POST resp.i = CkHttp::ckPostJson2(http,"https://graph.microsoft.com/v1.0/me/events","application/json",CkJsonObject::ckEmit(json)) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(json) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf Debug "Response status code = " + Str(CkHttpResponse::ckStatusCode(resp)) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(jResp,CkHttpResponse::ckBodyStr(resp)) CkJsonObject::setCkEmitCompact(jResp, 0) Debug CkJsonObject::ckEmit(jResp) CkHttpResponse::ckDispose(resp) ; The send succeeded if the response status code = 201. If CkHttpResponse::ckStatusCode(resp) <> 201 Debug "Failed" CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(json) CkCrypt2::ckDispose(crypt) CkJsonObject::ckDispose(jResp) ProcedureReturn 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 displayName.s locationType.s uniqueId.s uniqueIdType.s statusResponse.s statusTime.s emailAddressName.s emailAddressAddress.s odata_context.s = CkJsonObject::ckStringOf(jResp,Chr(34) + "@odata.context" + Chr(34)) odata_etag.s = CkJsonObject::ckStringOf(jResp,Chr(34) + "@odata.etag" + Chr(34)) id.s = CkJsonObject::ckStringOf(jResp,"id") createdDateTime.s = CkJsonObject::ckStringOf(jResp,"createdDateTime") lastModifiedDateTime.s = CkJsonObject::ckStringOf(jResp,"lastModifiedDateTime") changeKey.s = CkJsonObject::ckStringOf(jResp,"changeKey") transactionId.s = CkJsonObject::ckStringOf(jResp,"transactionId") originalStartTimeZone.s = CkJsonObject::ckStringOf(jResp,"originalStartTimeZone") originalEndTimeZone.s = CkJsonObject::ckStringOf(jResp,"originalEndTimeZone") iCalUId.s = CkJsonObject::ckStringOf(jResp,"iCalUId") reminderMinutesBeforeStart.i = CkJsonObject::ckIntOf(jResp,"reminderMinutesBeforeStart") isReminderOn.i = CkJsonObject::ckBoolOf(jResp,"isReminderOn") hasAttachments.i = CkJsonObject::ckBoolOf(jResp,"hasAttachments") subject.s = CkJsonObject::ckStringOf(jResp,"subject") bodyPreview.s = CkJsonObject::ckStringOf(jResp,"bodyPreview") importance.s = CkJsonObject::ckStringOf(jResp,"importance") sensitivity.s = CkJsonObject::ckStringOf(jResp,"sensitivity") isAllDay.i = CkJsonObject::ckBoolOf(jResp,"isAllDay") isCancelled.i = CkJsonObject::ckBoolOf(jResp,"isCancelled") isOrganizer.i = CkJsonObject::ckBoolOf(jResp,"isOrganizer") responseRequested.i = CkJsonObject::ckBoolOf(jResp,"responseRequested") seriesMasterId.s = CkJsonObject::ckStringOf(jResp,"seriesMasterId") showAs.s = CkJsonObject::ckStringOf(jResp,"showAs") v_type.s = CkJsonObject::ckStringOf(jResp,"type") webLink.s = CkJsonObject::ckStringOf(jResp,"webLink") onlineMeetingUrl.s = CkJsonObject::ckStringOf(jResp,"onlineMeetingUrl") isOnlineMeeting.i = CkJsonObject::ckBoolOf(jResp,"isOnlineMeeting") onlineMeetingProvider.s = CkJsonObject::ckStringOf(jResp,"onlineMeetingProvider") allowNewTimeProposals.i = CkJsonObject::ckBoolOf(jResp,"allowNewTimeProposals") isDraft.i = CkJsonObject::ckBoolOf(jResp,"isDraft") hideAttendees.i = CkJsonObject::ckBoolOf(jResp,"hideAttendees") recurrence.s = CkJsonObject::ckStringOf(jResp,"recurrence") onlineMeeting.s = CkJsonObject::ckStringOf(jResp,"onlineMeeting") responseStatusResponse.s = CkJsonObject::ckStringOf(jResp,"responseStatus.response") responseStatusTime.s = CkJsonObject::ckStringOf(jResp,"responseStatus.time") bodyContentType.s = CkJsonObject::ckStringOf(jResp,"body.contentType") bodyContent.s = CkJsonObject::ckStringOf(jResp,"body.content") startDateTime.s = CkJsonObject::ckStringOf(jResp,"start.dateTime") startTimeZone.s = CkJsonObject::ckStringOf(jResp,"start.timeZone") endDateTime.s = CkJsonObject::ckStringOf(jResp,"end.dateTime") endTimeZone.s = CkJsonObject::ckStringOf(jResp,"end.timeZone") locationDisplayName.s = CkJsonObject::ckStringOf(jResp,"location.displayName") locationLocationType.s = CkJsonObject::ckStringOf(jResp,"location.locationType") locationUniqueId.s = CkJsonObject::ckStringOf(jResp,"location.uniqueId") locationUniqueIdType.s = CkJsonObject::ckStringOf(jResp,"location.uniqueIdType") organizerEmailAddressName.s = CkJsonObject::ckStringOf(jResp,"organizer.emailAddress.name") organizerEmailAddressAddress.s = CkJsonObject::ckStringOf(jResp,"organizer.emailAddress.address") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"categories") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"locations") While i < count_i CkJsonObject::setCkI(jResp, i) displayName = CkJsonObject::ckStringOf(jResp,"locations[i].displayName") locationType = CkJsonObject::ckStringOf(jResp,"locations[i].locationType") uniqueId = CkJsonObject::ckStringOf(jResp,"locations[i].uniqueId") uniqueIdType = CkJsonObject::ckStringOf(jResp,"locations[i].uniqueIdType") i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"attendees") While i < count_i CkJsonObject::setCkI(jResp, i) v_type = CkJsonObject::ckStringOf(jResp,"attendees[i].type") statusResponse = CkJsonObject::ckStringOf(jResp,"attendees[i].status.response") statusTime = CkJsonObject::ckStringOf(jResp,"attendees[i].status.time") emailAddressName = CkJsonObject::ckStringOf(jResp,"attendees[i].emailAddress.name") emailAddressAddress = CkJsonObject::ckStringOf(jResp,"attendees[i].emailAddress.address") i = i + 1 Wend Debug "Event created." CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(json) CkCrypt2::ckDispose(crypt) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.