Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, HttpResponse, JsonObject, Crypt2;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
json: HCkJsonObject;
crypt: HCkCrypt2;
resp: HCkHttpResponse;
jResp: HCkJsonObject;
displayName: PWideChar;
locationType: PWideChar;
uniqueId: PWideChar;
uniqueIdType: PWideChar;
statusResponse: PWideChar;
statusTime: PWideChar;
emailAddressName: PWideChar;
emailAddressAddress: PWideChar;
odata_context: PWideChar;
odata_etag: PWideChar;
id: PWideChar;
createdDateTime: PWideChar;
lastModifiedDateTime: PWideChar;
changeKey: PWideChar;
transactionId: PWideChar;
originalStartTimeZone: PWideChar;
originalEndTimeZone: PWideChar;
iCalUId: PWideChar;
reminderMinutesBeforeStart: Integer;
isReminderOn: Boolean;
hasAttachments: Boolean;
subject: PWideChar;
bodyPreview: PWideChar;
importance: PWideChar;
sensitivity: PWideChar;
isAllDay: Boolean;
isCancelled: Boolean;
isOrganizer: Boolean;
responseRequested: Boolean;
seriesMasterId: PWideChar;
showAs: PWideChar;
v_type: PWideChar;
webLink: PWideChar;
onlineMeetingUrl: PWideChar;
isOnlineMeeting: Boolean;
onlineMeetingProvider: PWideChar;
allowNewTimeProposals: Boolean;
isDraft: Boolean;
hideAttendees: Boolean;
recurrence: PWideChar;
onlineMeeting: 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 here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/outlookCalendar.json');
if (success = False) then
  begin
    Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken));
    Exit;
  end;

CkHttp_putAuthToken(http,CkJsonObject__stringOf(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 := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'subject','Let''s go for lunch');
CkJsonObject_UpdateString(json,'body.contentType','HTML');
CkJsonObject_UpdateString(json,'body.content','Does noon work for you?');
CkJsonObject_UpdateString(json,'start.dateTime','2021-05-15T12:00:00');
CkJsonObject_UpdateString(json,'start.timeZone','Pacific Standard Time');
CkJsonObject_UpdateString(json,'end.dateTime','2021-05-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','samanthab@contoso.onmicrosoft.com');
CkJsonObject_UpdateString(json,'attendees[0].emailAddress.name','Samantha Booth');
CkJsonObject_UpdateString(json,'attendees[0].type','required');
CkJsonObject_UpdateBool(json,'allowNewTimeProposals',True);

// Generate a UUID.
crypt := CkCrypt2_Create();
CkJsonObject_UpdateString(json,'transactionId',CkCrypt2__generateUuid(crypt));

// Add the "Prefer" request header.
CkHttp_SetRequestHeader(http,'Prefer','outlook.timezone="Pacific Standard Time"');

// Send the HTTP POST
resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://graph.microsoft.com/v1.0/me/events',json,'application/json',resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add('Response status code = ' + IntToStr(CkHttpResponse_getStatusCode(resp)));

jResp := CkJsonObject_Create();
CkJsonObject_Load(jResp,CkHttpResponse__bodyStr(resp));
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add(CkJsonObject__emit(jResp));

// The send succeeded if the response status code = 201.
if (CkHttpResponse_getStatusCode(resp) <> 201) then
  begin
    Memo1.Lines.Add('Failed');
    Exit;
  end;

// 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

odata_context := CkJsonObject__stringOf(jResp,'"@odata.context"');
odata_etag := CkJsonObject__stringOf(jResp,'"@odata.etag"');
id := CkJsonObject__stringOf(jResp,'id');
createdDateTime := CkJsonObject__stringOf(jResp,'createdDateTime');
lastModifiedDateTime := CkJsonObject__stringOf(jResp,'lastModifiedDateTime');
changeKey := CkJsonObject__stringOf(jResp,'changeKey');
transactionId := CkJsonObject__stringOf(jResp,'transactionId');
originalStartTimeZone := CkJsonObject__stringOf(jResp,'originalStartTimeZone');
originalEndTimeZone := CkJsonObject__stringOf(jResp,'originalEndTimeZone');
iCalUId := CkJsonObject__stringOf(jResp,'iCalUId');
reminderMinutesBeforeStart := CkJsonObject_IntOf(jResp,'reminderMinutesBeforeStart');
isReminderOn := CkJsonObject_BoolOf(jResp,'isReminderOn');
hasAttachments := CkJsonObject_BoolOf(jResp,'hasAttachments');
subject := CkJsonObject__stringOf(jResp,'subject');
bodyPreview := CkJsonObject__stringOf(jResp,'bodyPreview');
importance := CkJsonObject__stringOf(jResp,'importance');
sensitivity := CkJsonObject__stringOf(jResp,'sensitivity');
isAllDay := CkJsonObject_BoolOf(jResp,'isAllDay');
isCancelled := CkJsonObject_BoolOf(jResp,'isCancelled');
isOrganizer := CkJsonObject_BoolOf(jResp,'isOrganizer');
responseRequested := CkJsonObject_BoolOf(jResp,'responseRequested');
seriesMasterId := CkJsonObject__stringOf(jResp,'seriesMasterId');
showAs := CkJsonObject__stringOf(jResp,'showAs');
v_type := CkJsonObject__stringOf(jResp,'type');
webLink := CkJsonObject__stringOf(jResp,'webLink');
onlineMeetingUrl := CkJsonObject__stringOf(jResp,'onlineMeetingUrl');
isOnlineMeeting := CkJsonObject_BoolOf(jResp,'isOnlineMeeting');
onlineMeetingProvider := CkJsonObject__stringOf(jResp,'onlineMeetingProvider');
allowNewTimeProposals := CkJsonObject_BoolOf(jResp,'allowNewTimeProposals');
isDraft := CkJsonObject_BoolOf(jResp,'isDraft');
hideAttendees := CkJsonObject_BoolOf(jResp,'hideAttendees');
recurrence := CkJsonObject__stringOf(jResp,'recurrence');
onlineMeeting := CkJsonObject__stringOf(jResp,'onlineMeeting');
responseStatusResponse := CkJsonObject__stringOf(jResp,'responseStatus.response');
responseStatusTime := CkJsonObject__stringOf(jResp,'responseStatus.time');
bodyContentType := CkJsonObject__stringOf(jResp,'body.contentType');
bodyContent := CkJsonObject__stringOf(jResp,'body.content');
startDateTime := CkJsonObject__stringOf(jResp,'start.dateTime');
startTimeZone := CkJsonObject__stringOf(jResp,'start.timeZone');
endDateTime := CkJsonObject__stringOf(jResp,'end.dateTime');
endTimeZone := CkJsonObject__stringOf(jResp,'end.timeZone');
locationDisplayName := CkJsonObject__stringOf(jResp,'location.displayName');
locationLocationType := CkJsonObject__stringOf(jResp,'location.locationType');
locationUniqueId := CkJsonObject__stringOf(jResp,'location.uniqueId');
locationUniqueIdType := CkJsonObject__stringOf(jResp,'location.uniqueIdType');
organizerEmailAddressName := CkJsonObject__stringOf(jResp,'organizer.emailAddress.name');
organizerEmailAddressAddress := CkJsonObject__stringOf(jResp,'organizer.emailAddress.address');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'categories');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'locations');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    displayName := CkJsonObject__stringOf(jResp,'locations[i].displayName');
    locationType := CkJsonObject__stringOf(jResp,'locations[i].locationType');
    uniqueId := CkJsonObject__stringOf(jResp,'locations[i].uniqueId');
    uniqueIdType := CkJsonObject__stringOf(jResp,'locations[i].uniqueIdType');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'attendees');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    v_type := CkJsonObject__stringOf(jResp,'attendees[i].type');
    statusResponse := CkJsonObject__stringOf(jResp,'attendees[i].status.response');
    statusTime := CkJsonObject__stringOf(jResp,'attendees[i].status.time');
    emailAddressName := CkJsonObject__stringOf(jResp,'attendees[i].emailAddress.name');
    emailAddressAddress := CkJsonObject__stringOf(jResp,'attendees[i].emailAddress.address');
    i := i + 1;
  end;

Memo1.Lines.Add('Event created.');

CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_Dispose(json);
CkCrypt2_Dispose(crypt);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(jResp);

end;