Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpResponse, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
json: HCkJsonObject;
resp: HCkHttpResponse;
displayName: PWideChar;
locationType: PWideChar;
uniqueId: PWideChar;
uniqueIdType: PWideChar;
statusResponse: PWideChar;
statusTime: PWideChar;
emailAddressName: PWideChar;
emailAddressAddress: PWideChar;
odataContext: PWideChar;
odataEtag: PWideChar;
id: PWideChar;
createdDateTime: PWideChar;
lastModifiedDateTime: PWideChar;
changeKey: PWideChar;
originalStartTimeZone: PWideChar;
originalEndTimeZone: PWideChar;
iCalUId: PWideChar;
reminderMinutesBeforeStart: PWideChar;
isReminderOn: PWideChar;
hasAttachments: PWideChar;
subject: PWideChar;
bodyPreview: PWideChar;
importance: PWideChar;
sensitivity: PWideChar;
isAllDay: PWideChar;
isCancelled: PWideChar;
isOrganizer: PWideChar;
responseRequested: PWideChar;
seriesMasterId: PWideChar;
showAs: PWideChar;
type: PWideChar;
webLink: PWideChar;
onlineMeetingUrl: PWideChar;
recurrence: PWideChar;
responseStatusResponse: PWideChar;
responseStatusTime: PWideChar;
bodyContentType: PWideChar;
bodyContent: PWideChar;
startDateTime: PWideChar;
startTimeZone: PWideChar;
endDateTime: PWideChar;
endTimeZone: PWideChar;
locationDisplayName: PWideChar;
locationLocationType: PWideChar;
locationUniqueId: PWideChar;
locationUniqueIdType: PWideChar;
organizerEmailAddressName: PWideChar;
organizerEmailAddressAddress: PWideChar;
i: Integer;
count_i: Integer;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/msGraphCalendar.json');
if (success = False) then
begin
Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken));
Exit;
end;
CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'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"
// }
// ]
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'subject','Let''s go for lunch');
CkJsonObject_UpdateString(json,'body.contentType','HTML');
CkJsonObject_UpdateString(json,'body.content','Does mid month work for you?');
CkJsonObject_UpdateString(json,'start.dateTime','2019-11-15T12:00:00');
CkJsonObject_UpdateString(json,'start.timeZone','Pacific Standard Time');
CkJsonObject_UpdateString(json,'end.dateTime','2019-11-15T14:00:00');
CkJsonObject_UpdateString(json,'end.timeZone','Pacific Standard Time');
CkJsonObject_UpdateString(json,'location.displayName','Harry''s Bar');
CkJsonObject_UpdateString(json,'attendees[0].emailAddress.address','adelev@contoso.onmicrosoft.com');
CkJsonObject_UpdateString(json,'attendees[0].emailAddress.name','Adele Vance');
CkJsonObject_UpdateString(json,'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
CkHttp_SetUrlVar(http,'id','AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==');
resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://graph.microsoft.com/v1.0/me/calendars/{$id}/events',json,'application/json',resp);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
CkJsonObject_Load(json,CkHttpResponse__bodyStr(resp));
CkJsonObject_putEmitCompact(json,False);
if (CkHttpResponse_getStatusCode(resp) <> 201) then
begin
Memo1.Lines.Add(CkJsonObject__emit(json));
Memo1.Lines.Add('Failed, response status code = ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
Exit;
end;
Memo1.Lines.Add(CkJsonObject__emit(json));
// 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
odataContext := CkJsonObject__stringOf(json,'"@odata.context"');
odataEtag := CkJsonObject__stringOf(json,'"@odata.etag"');
id := CkJsonObject__stringOf(json,'id');
createdDateTime := CkJsonObject__stringOf(json,'createdDateTime');
lastModifiedDateTime := CkJsonObject__stringOf(json,'lastModifiedDateTime');
changeKey := CkJsonObject__stringOf(json,'changeKey');
originalStartTimeZone := CkJsonObject__stringOf(json,'originalStartTimeZone');
originalEndTimeZone := CkJsonObject__stringOf(json,'originalEndTimeZone');
iCalUId := CkJsonObject__stringOf(json,'iCalUId');
reminderMinutesBeforeStart := CkJsonObject_IntOf(json,'reminderMinutesBeforeStart');
isReminderOn := CkJsonObject_BoolOf(json,'isReminderOn');
hasAttachments := CkJsonObject_BoolOf(json,'hasAttachments');
subject := CkJsonObject__stringOf(json,'subject');
bodyPreview := CkJsonObject__stringOf(json,'bodyPreview');
importance := CkJsonObject__stringOf(json,'importance');
sensitivity := CkJsonObject__stringOf(json,'sensitivity');
isAllDay := CkJsonObject_BoolOf(json,'isAllDay');
isCancelled := CkJsonObject_BoolOf(json,'isCancelled');
isOrganizer := CkJsonObject_BoolOf(json,'isOrganizer');
responseRequested := CkJsonObject_BoolOf(json,'responseRequested');
seriesMasterId := CkJsonObject__stringOf(json,'seriesMasterId');
showAs := CkJsonObject__stringOf(json,'showAs');
type := CkJsonObject__stringOf(json,'type');
webLink := CkJsonObject__stringOf(json,'webLink');
onlineMeetingUrl := CkJsonObject__stringOf(json,'onlineMeetingUrl');
recurrence := CkJsonObject__stringOf(json,'recurrence');
responseStatusResponse := CkJsonObject__stringOf(json,'responseStatus.response');
responseStatusTime := CkJsonObject__stringOf(json,'responseStatus.time');
bodyContentType := CkJsonObject__stringOf(json,'body.contentType');
bodyContent := CkJsonObject__stringOf(json,'body.content');
startDateTime := CkJsonObject__stringOf(json,'start.dateTime');
startTimeZone := CkJsonObject__stringOf(json,'start.timeZone');
endDateTime := CkJsonObject__stringOf(json,'end.dateTime');
endTimeZone := CkJsonObject__stringOf(json,'end.timeZone');
locationDisplayName := CkJsonObject__stringOf(json,'location.displayName');
locationLocationType := CkJsonObject__stringOf(json,'location.locationType');
locationUniqueId := CkJsonObject__stringOf(json,'location.uniqueId');
locationUniqueIdType := CkJsonObject__stringOf(json,'location.uniqueIdType');
organizerEmailAddressName := CkJsonObject__stringOf(json,'organizer.emailAddress.name');
organizerEmailAddressAddress := CkJsonObject__stringOf(json,'organizer.emailAddress.address');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'categories');
while i < count_i do
begin
CkJsonObject_putI(json,i);
// ...
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'locations');
while i < count_i do
begin
CkJsonObject_putI(json,i);
displayName := CkJsonObject__stringOf(json,'locations[i].displayName');
locationType := CkJsonObject__stringOf(json,'locations[i].locationType');
uniqueId := CkJsonObject__stringOf(json,'locations[i].uniqueId');
uniqueIdType := CkJsonObject__stringOf(json,'locations[i].uniqueIdType');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'attendees');
while i < count_i do
begin
CkJsonObject_putI(json,i);
type := CkJsonObject__stringOf(json,'attendees[i].type');
statusResponse := CkJsonObject__stringOf(json,'attendees[i].status.response');
statusTime := CkJsonObject__stringOf(json,'attendees[i].status.time');
emailAddressName := CkJsonObject__stringOf(json,'attendees[i].emailAddress.name');
emailAddressAddress := CkJsonObject__stringOf(json,'attendees[i].emailAddress.address');
i := i + 1;
end;
Memo1.Lines.Add('Success.');
CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
end;