Outlook Contacts API Guide
An Outlook contact stores information such as names, email addresses, phone numbers, postal addresses, and a photo in a mailbox contact folder. Microsoft Graph provides REST endpoints to read and manage these contacts in Outlook.com and Microsoft 365. This guide links to 14 complete examples using direct Chilkat.Http calls.
Choose a language to update all 14 example links below. Each link opens the complete example in that language. The guide text stays the same.
These examples work with mailbox contacts, not Microsoft Entra directory users, organizational contacts at /contacts, or the People API. Outlook does not need to be running. The requests address the online mailbox rather than a local Outlook installation or PST file. See Microsoft's contact resource reference.
Use Chilkat 11.6.0 or later and an unlocked library. The examples target the global-cloud endpoint https://graph.microsoft.com/v1.0. Begin with authorization, list contacts, and save the returned string IDs with their mailbox context. For contacts outside the default folder, list the folders and select the appropriate folder ID.
| Request | Chilkat operation |
|---|---|
| Bearer authentication | Set Http.AuthToken to the access-token value, without the Bearer prefix. |
| GET or DELETE without a body | Use Http.HttpNoBody with the verb, URL, and an HttpResponse. |
| POST or PATCH with JSON | Build a JsonObject and call Http.HttpJson with application/json. |
| JSON or photo response | Check StatusCode first. Parse JSON with JsonObject.Strict enabled; read photo bytes with HttpResponse.GetBodyBd. |
Authorization
Register an application in Microsoft Entra and choose the account types it supports. Delegated authorization works with supported personal Outlook.com and Microsoft 365 work/school accounts. Application authentication is for administrator-authorized Microsoft 365 access without a signed-in user.
| Model | Mailbox context | Continuing access |
|---|---|---|
| Delegated OAuth2 | /me addresses the signed-in user. Request Contacts.Read or Contacts.ReadWrite as needed. | After initial authorization, use a refresh token. Sign-in can be required again. |
| Application credentials | Use /users/{id-or-UPN} for an explicitly authorized organizational mailbox. Application permissions require administrator consent. | Obtain a new access token with a fresh certificate assertion; no refresh token is issued. |
Interactive authorization and refresh
The OAuth2 example uses a system browser and PKCE with S256. Register http://localhost:3017/ under Mobile and desktop applications. Chilkat receives the local callback; this does not require a hosted web server. A public desktop app does not keep a client secret. Choose common, consumers, organizations, or a tenant-specific authority to match the app registration and intended users. Both endpoints must use the same authority. Microsoft authorization-code flow.
The example requests offline_access and Contacts.ReadWrite to cover the collection's writes. Use Contacts.Read for read-only operations. Delegated examples read qa_data/tokens/outlookContacts.json. Keep the cache private and associated with its app and account. A calendar token without the needed contacts permission, or a token for SMTP or another resource, is insufficient.
The refresh example uses the original client ID and authority. It validates the response, saves a rotated refresh token when returned, and retains the old one when the field is absent. Refresh before the recorded acquired time plus expires_in lifetime elapses. Revocation or an interaction requirement needs a new sign-in. Production code should protect credentials, serialize refreshes, and replace the cache atomically. Web and mobile applications need redirect handling appropriate to their environment.
Unattended Microsoft 365 access
The certificate example requests a token from a tenant-specific endpoint with the Graph .default scope. Grant application Contacts.Read for its listing operation, or Contacts.ReadWrite for required writes, with administrator consent. Restrict mailbox access using the organization's supported Exchange application-access controls. This flow is not available for personal Outlook.com mailboxes.
Upload the public certificate to the app registration and protect the RSA private key. Private outlook-contacts-app.json supplies the tenant ID, client ID, mailbox, PFX path, and PFX password. The example signs a short-lived PS256 assertion with an x5t#S256 certificate thumbprint. That assertion goes to the token endpoint; the resulting access token goes to Graph. Microsoft certificate-credentials documentation.
Contacts
List, find, and retrieve
/me/contacts lists the default Contacts folder; it does not recursively list every folder. For a selected folder, use /me/contactFolders/{folderId}/contacts. The listing example selects useful fields, follows every @odata.nextLink, and handles multiple email addresses and phone numbers. An empty page can still have a continuation. The complete nextLink must be used unchanged. List contacts and supported query options.
To find an email address, use the documented emailAddresses/any(a:a/address eq '...') filter. The search example doubles apostrophes inside the OData string literal, then URL-encodes the complete filter value. This address filter supports eq; do not replace it with startswith. It reports all matches because email addresses and display names are not unique identifiers.
Retrieve a specific contact using its ID and $select for the needed fields. The example demonstrates optional scalar values, a structured address, and email and phone collections. Preserve phone numbers as strings. Store contact IDs as case-sensitive strings and encode each ID separately when constructing a URL path. Keep the mailbox context alongside the ID.
The contact examples request Prefer: IdType="ImmutableId" consistently. These IDs remain stable when a contact moves between folders in the same mailbox; they are not a universal identity across mailboxes or export/import operations. Retain the preference on subsequent requests, including pagination. Existing stored default-format IDs need deliberate conversion or fresh retrieval. Immutable Outlook identifiers.
Create, update, and delete
Creating a contact stores names, email-address objects, and phone-number arrays in the mailbox. It does not send mail or an invitation. Save the returned ID after HTTP 201. The creation example records a pending attempt before POST and a receipt after success. Contacts have no event-style transactionId deduplication property, so an uncertain creation must be reconciled before another POST. A failed receipt write does not undo server creation. Create a contact.
The update example retrieves the current displayName and includes it in the PATCH to preserve a custom value. It supplies all five homeAddress components when replacing that structured property, and represents birthday as a DateTimeOffset with a UTC offset. To change one address component, retrieve the existing address and construct the full desired replacement. When changing an email or phone collection, supply the desired full collection. Omit unrelated properties. The preliminary GET does not lock the contact. Contact update rules.
Download a photo
The photo example requests /me/contacts/{id}/photo/$value. It downloads the contact's photo rather than the signed-in user's profile photo. A successful response is binary image data, not JSON. The code checks HTTP status, JPEG content type, and a nonempty body before saving. Missing photos normally return 404, but an incorrect contact ID can do the same. The example leaves an existing photo file untouched on these response errors; a successful save replaces it. Contact photo API.
Contact Folders
Contact folders organize a mailbox's saved contacts. The folder-list example starts with /me/contactFolders, then uses a queue to visit each discovered folder's childFolders. It handles pagination at every level and avoids traversing the same folder twice. Preserve folder IDs and parentFolderId values to reconstruct the hierarchy. A folder's name is a display label, not a unique key. Contact folder resources.
The traversal lists folders, not their contents. Use the existing contact-list example with each chosen folder ID to read its contacts. Default-folder contacts are read through /me/contacts; a contact's parentFolderId identifies its containing folder. The traversal stops at 100 total HTTP requests and reports incomplete work. Persist its pending queue, position, and processed-folder set to resume a larger traversal.
The management example performs one selected action: create, rename, or delete. Creation can specify a parent folder to make a child folder. It saves a pending attempt before sending and records the returned folder ID afterward. Reconcile an uncertain result rather than creating a duplicate. Rename and delete use an explicitly selected custom folder; do not target the default Contacts folder. Deleting a folder affects its contacts and child folders. Inspect those contents before choosing deletion.
Shared Contacts
Reading another mailbox's contact folder requires actual sharing or delegation rights and appropriate delegated consent. Change the authorization example's scope to offline_access https://graph.microsoft.com/Contacts.Read.Shared, or Contacts.ReadWrite.Shared for writes, and obtain consent. Adding the scope does not itself create folder access.
The example addresses /users/{owner}/contactFolders/{folderId}/contacts. Supply the owner's object ID or UPN and the folder ID in that owner's context. Retain that owner with returned contact IDs rather than using them against the recipient's /me path. A 403 can indicate missing folder rights, missing consent, or tenant policy. Administrator-granted application access is a separate model. This example reads the folder directly and needs no webhook receiver. Shared and delegated contact folders.
Synchronization
Use contact delta queries to maintain a local copy of selected fields in one folder. The initial /me/contactFolders/{id}/contacts/delta request establishes a baseline. Follow each nextLink within that round, then save the final deltaLink to retrieve changes on a later run. Preserve the exact URLs, field selection, and ID preference; do not rebuild opaque tokens or append the original query options again. A separate checkpoint is needed for each folder.
Apply returned additions and updates by string contact ID. An @removed entry removes the contact from the tracked folder view; it may reflect a move out of the folder rather than global deletion. The example marks such records with removed=true. Contact delta requests and continuation links.
The sample cache stores id, displayName, emailAddresses, and mobilePhone. Hashes are used only for JSON-safe local keys; the original ID is retained. Partial updates preserve omitted fields, explicit nulls clear scalar values, and a present email array replaces the previous array, including an empty array that clears it. This is a small local projection rather than a complete contact archive.
Each checkpoint saves data and its continuation URL together, with a backup of the previous matching pair. HTTP or validation failures do not advance the cursor. Recover the backup if the main file is damaged; replaying a page updates the same records. Production storage should commit data and cursor atomically with one writer per account and folder. The example checks the folder ID and pauses after 100 pages with a continuation saved. Rejected or expired sync state requires a new baseline and deliberate reconciliation of the old view.
Across the collection, handle 401 by refreshing or authorizing again, investigate permissions and mailbox access for 403, and honor Retry-After on 429 before a bounded retry. A timeout or 5xx response to a write can leave the outcome uncertain; reconcile before repeating it. Protect tokens, contact caches, photos, and detailed diagnostics. The examples use polling and direct requests, so none requires a webhook receiver.