Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.6.0+

Outlook Calendar: Create a Meeting with Attendees and Optional Teams

See more Outlook Calendar Examples

Sends invitations: replace attendee@example.com with an intended recipient before running. Graph sends invitations when attendees are supplied. This example creates a one-hour meeting tomorrow and saves its ID. The responseRequested property asks attendees for responses; it is not a switch to suppress the invitations.

Set enableTeams=true for a supported Microsoft 365 calendar. The example checks allowedOnlineMeetingProviders before creating a new request, sets isOnlineMeeting and teamsForBusiness, and reads onlineMeeting.joinUrl. This uses the calendar API, not the standalone onlineMeetings API. With enableTeams=false it creates an ordinary meeting. A persisted request retains its original settings on retry; do not change settings underneath the same transaction ID.

Live creation: this posts a real calendar item. The request file is saved before sending, including its transactionId, and a receipt records the returned ID. Reuse the saved payload after an uncertain outcome; use a new filename pair for a deliberately new operation. A saved receipt prevents repeat creation on a later successful run. Keep request/receipt files private, per account, and use one writer. See the basic creation example for the same pattern.

Delegated permission: Calendars.ReadWrite.

Uses Microsoft Graph v1.0 in the global cloud with a delegated access token saved by the calendar OAuth2 example. Both personal Outlook.com accounts and Microsoft 365 work/school accounts with a mailbox can use this flow. The app registration must support the selected account type. A token for SMTP/IMAP/POP or another API is not a Graph token.

/me means the signed-in user and requires delegated authentication. An unattended Microsoft 365 service instead needs application permissions and administrator consent, and addresses an explicit mailbox through /users/{id-or-userPrincipalName}. That client-credentials flow does not apply to personal Outlook.com accounts. These samples target the global cloud; national clouds use different authority and Graph hosts.

HTTP methods can return false for an HTTP error as well as a connection failure. The code distinguishes those cases and checks the expected status before reading JSON. For 401, refresh the access token or authorize again; for 403, check permissions, mailbox access, and tenant policy. For 429, honor Retry-After before a bounded retry. Do not automatically repeat a write after an uncertain outcome. Keep detailed errors and calendar data private.

Microsoft documentation

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
token: HCkJsonObject;
http: HCkHttp;
resp: HCkHttpResponse;
result: HCkJsonObject;
requestFile: PWideChar;
resultFile: PWideChar;
fac: HCkFileAccess;
enableTeams: Boolean;
body: HCkJsonObject;
teamsAllowed: Boolean;
providerIndex: Integer;
when: HCkDateTime;
crypt: HCkCrypt2;
transactionId: PWideChar;
receipt: HCkJsonObject;
saved: HCkJsonObject;

begin
success := False;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
success := False;
//  Obtain a delegated Microsoft Graph token using the calendar authorization example.
//  See Authorize Outlook Calendar with OAuth2 and PKCE.
token := CkJsonObject_Create();
CkJsonObject_putStrict(token,True);
success := CkJsonObject_LoadFile(token,'qa_data/tokens/outlookCalendar.json');
if (success <> True) then
  begin
    Memo1.Lines.Add('Could not read the private calendar token cache.');
    Exit;
  end;
if ((CkJsonObject_JsonTypeOf(token,'access_token') <> 1) or (CkJsonObject_StringOfEquals(token,'access_token','',True) = True)) then
  begin
    Memo1.Lines.Add('Expected a nonempty access_token in the JSON.');
    Exit;
  end;
http := CkHttp_Create();
CkHttp_putAuthToken(http,CkJsonObject__stringOf(token,'access_token'));
CkHttp_putRequireSslCertVerify(http,True);
CkHttp_putFollowRedirects(http,False);
CkHttp_putConnectTimeout(http,20);
CkHttp_putReadTimeout(http,30);
CkHttp_SetRequestHeader(http,'Accept','application/json');
resp := CkHttpResponse_Create();
result := CkJsonObject_Create();
CkJsonObject_putStrict(result,True);
CkHttp_SetRequestHeader(http,'Prefer','outlook.timezone="UTC", IdType="ImmutableId"');
//  Live write: creates a meeting and sends invitations in the signed-in user's default calendar.
//  Keep one request file per logical operation and account. Do not run concurrent copies.
requestFile := 'qa_data/outlookCalendar/create-meeting-request.json';
resultFile := 'qa_data/outlookCalendar/created-meeting.json';
fac := CkFileAccess_Create();
success := CkFileAccess_DirEnsureExists(fac,'qa_data/outlookCalendar');
if (success <> True) then
  begin
    Memo1.Lines.Add('Could not create the private operation directory.');
    Exit;
  end;
//  Set true only for a Teams-enabled organizational calendar.
enableTeams := False;
body := CkJsonObject_Create();
CkJsonObject_putStrict(body,True);
if (CkFileAccess_FileExists(fac,requestFile) = True) then
  begin
    success := CkJsonObject_LoadFile(body,requestFile);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not read the saved create request; nothing sent.');
        Exit;
      end;
    //  Retry the same saved body and transactionId after an uncertain result.
  end
else
  begin
    if (enableTeams = True) then
      begin
        success := CkHttp_HttpNoBody(http,'GET','https://graph.microsoft.com/v1.0/me/calendar?$select=allowedOnlineMeetingProviders',resp);
        //  A false result can still include an HTTP error response.
        if ((success <> True) and (CkHttpResponse_getStatusCode(resp) = 0)) then
          begin
            Memo1.Lines.Add('No HTTP response was received. Inspect diagnostics privately; reconcile a write before retrying.');
            Exit;
          end;
        if (CkHttpResponse_getStatusCode(resp) <> 200) then
          begin
            Memo1.Lines.Add('Unexpected HTTP status: ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
            Memo1.Lines.Add('Request ID: ' + CkHttpResponse__getHeaderField(resp,'request-id'));
            if (CkHttpResponse_getStatusCode(resp) = 429) then
              begin
                Memo1.Lines.Add('Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
              end;
            if (CkHttpResponse_getStatusCode(resp) = 401) then
              begin
                Memo1.Lines.Add('Refresh the Graph access token or authorize again.');
              end;
            Exit;
          end;
        success := CkJsonObject_Load(result,CkHttpResponse__bodyStr(resp));
        if (success <> True) then
          begin
            Memo1.Lines.Add('Expected a well-formed JSON response.');
            Exit;
          end;
        if (CkJsonObject_JsonTypeOf(result,'allowedOnlineMeetingProviders') <> 4) then
          begin
            Memo1.Lines.Add('Could not determine supported meeting providers.');
            Exit;
          end;
        teamsAllowed := False;
        providerIndex := 0;
        while (providerIndex < CkJsonObject_SizeOfArray(result,'allowedOnlineMeetingProviders')) do
          begin
            CkJsonObject_putI(result,providerIndex);
            if (CkJsonObject_StringOfEquals(result,'allowedOnlineMeetingProviders[i]','teamsForBusiness',True) = True) then
              begin
                teamsAllowed := True;
              end;
            providerIndex := providerIndex + 1;
          end;

        if (teamsAllowed <> True) then
          begin
            Memo1.Lines.Add('This calendar does not list Teams as an allowed provider; nothing created.');
            Exit;
          end;
        CkJsonObject_UpdateBool(body,'isOnlineMeeting',True);
        CkJsonObject_UpdateString(body,'onlineMeetingProvider','teamsForBusiness');
      end;
    when := CkDateTime_Create();
    success := CkDateTime_SetFromCurrentSystemTime(when);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not get the time.');
        Exit;
      end;
    success := CkDateTime_AddDays(when,1);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not calculate tomorrow.');
        Exit;
      end;
    CkJsonObject_UpdateString(body,'subject','Sample meeting');
    CkJsonObject_UpdateString(body,'body.contentType','text');
    CkJsonObject_UpdateString(body,'body.content','Sample event details.');
    CkJsonObject_UpdateString(body,'start.dateTime',CkDateTime__getAsIso8601(when,'YYYY-MM-DDThh:mm:ss',False));
    CkJsonObject_UpdateString(body,'start.timeZone','UTC');
    success := CkDateTime_AddSeconds(when,3600);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not calculate the end.');
        Exit;
      end;
    CkJsonObject_UpdateString(body,'end.dateTime',CkDateTime__getAsIso8601(when,'YYYY-MM-DDThh:mm:ss',False));
    CkJsonObject_UpdateString(body,'end.timeZone','UTC');
    CkJsonObject_UpdateString(body,'attendees[0].emailAddress.address','attendee@example.com');
    CkJsonObject_UpdateString(body,'attendees[0].type','required');
    CkJsonObject_UpdateBool(body,'responseRequested',True);
    //  Adding attendees sends real invitations. Replace the sample address before running.
    crypt := CkCrypt2_Create();
    transactionId := CkCrypt2__generateUuid(crypt);
    if (CkCrypt2_getLastMethodSuccess(crypt) <> True) then
      begin
        Memo1.Lines.Add('Could not create a transaction ID.');
        Exit;
      end;
    CkJsonObject_UpdateString(body,'transactionId',transactionId);
    success := CkJsonObject_WriteFile(body,requestFile);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not save the request before sending; nothing sent.');
        Exit;
      end;
  end;
if ((CkJsonObject_JsonTypeOf(body,'transactionId') <> 1) or (CkJsonObject_StringOfEquals(body,'transactionId','',True) = True)) then
  begin
    Memo1.Lines.Add('Expected a nonempty transactionId in the JSON.');
    Exit;
  end;
//  A previous successful run leaves a small receipt. Do not submit it again.
if (CkFileAccess_FileExists(fac,resultFile) = True) then
  begin
    receipt := CkJsonObject_Create();
    CkJsonObject_putStrict(receipt,True);
    success := CkJsonObject_LoadFile(receipt,resultFile);
    if (success <> True) then
      begin
        Memo1.Lines.Add('Could not read the existing receipt; nothing sent.');
        Exit;
      end;
    if ((CkJsonObject_JsonTypeOf(receipt,'id') <> 1) or (CkJsonObject_StringOfEquals(receipt,'id','',True) = True)) then
      begin
        Memo1.Lines.Add('Expected a nonempty id in the JSON.');
        Exit;
      end;
    if (CkJsonObject_StringOfEquals(receipt,'transactionId',CkJsonObject__stringOf(body,'transactionId'),True) <> True) then
      begin
        Memo1.Lines.Add('The receipt belongs to another operation; nothing sent.');
        Exit;
      end;
    Memo1.Lines.Add('Already created event ID: ' + CkJsonObject__stringOf(receipt,'id'));
    Exit;
  end;
success := CkHttp_HttpJson(http,'POST','https://graph.microsoft.com/v1.0/me/events',body,'application/json',resp);
//  A false result can still include an HTTP error response.
if ((success <> True) and (CkHttpResponse_getStatusCode(resp) = 0)) then
  begin
    Memo1.Lines.Add('No HTTP response was received. Inspect diagnostics privately; reconcile a write before retrying.');
    Exit;
  end;
if (CkHttpResponse_getStatusCode(resp) <> 201) then
  begin
    Memo1.Lines.Add('Unexpected HTTP status: ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    Memo1.Lines.Add('Request ID: ' + CkHttpResponse__getHeaderField(resp,'request-id'));
    if (CkHttpResponse_getStatusCode(resp) = 429) then
      begin
        Memo1.Lines.Add('Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
      end;
    if (CkHttpResponse_getStatusCode(resp) = 401) then
      begin
        Memo1.Lines.Add('Refresh the Graph access token or authorize again.');
      end;
    Exit;
  end;
success := CkJsonObject_Load(result,CkHttpResponse__bodyStr(resp));
if (success <> True) then
  begin
    Memo1.Lines.Add('Expected a well-formed JSON response.');
    Exit;
  end;
if ((CkJsonObject_JsonTypeOf(result,'id') <> 1) or (CkJsonObject_StringOfEquals(result,'id','',True) = True)) then
  begin
    Memo1.Lines.Add('Expected a nonempty id in the JSON.');
    Exit;
  end;
saved := CkJsonObject_Create();
CkJsonObject_UpdateString(saved,'id',CkJsonObject__stringOf(result,'id'));
CkJsonObject_UpdateString(saved,'transactionId',CkJsonObject__stringOf(body,'transactionId'));
//  Display the ID even if saving the receipt fails: the server has already created the event.
Memo1.Lines.Add('Created event ID: ' + CkJsonObject__stringOf(result,'id'));
success := CkJsonObject_WriteFile(saved,resultFile);
if (success <> True) then
  begin
    Memo1.Lines.Add('The event was created, but its receipt could not be saved. Reconcile before retrying.');
    Exit;
  end;
Memo1.Lines.Add('Start: ' + CkJsonObject__stringOf(result,'start.dateTime') + ' (' + CkJsonObject__stringOf(result,'start.timeZone') + ')');
Memo1.Lines.Add('End: ' + CkJsonObject__stringOf(result,'end.dateTime') + ' (' + CkJsonObject__stringOf(result,'end.timeZone') + ')');
Memo1.Lines.Add('Event receipt saved.');
if (CkJsonObject_JsonTypeOf(result,'onlineMeeting.joinUrl') = 1) then
  begin
    Memo1.Lines.Add('Meeting join URL: ' + CkJsonObject__stringOf(result,'onlineMeeting.joinUrl'));
  end;

CkJsonObject_Dispose(token);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkFileAccess_Dispose(fac);
CkJsonObject_Dispose(body);
    CkDateTime_Dispose(when);
    CkCrypt2_Dispose(crypt);
    CkJsonObject_Dispose(receipt);
CkJsonObject_Dispose(saved);