README Create Contact #
What this does #
Creates a contact in the authenticated user’s default Outlook/M365 contacts folder via the Microsoft Graph /me/contacts endpoint, using OAuth2 with MFA. Supports first name, last name, email address, business phone, mobile phone, company name, job title, and department. Only first name is required — all other fields are optional and omitted from the payload if not supplied.
Office apps #
- Access (tested M365)
- Excel (untested M365)
Required components #
- VBAuth.dll v1.x
- modVBAuthGlobalConstants.bas (from /shared)
- modCreateContact.bas (this module)
Azure Entra App Registration #
Delegated permissions:
- Contacts.ReadWrite
VBAuth Admin Table – Required Values #
| Column Name | Required Value / Example | Notes |
|---|---|---|
| AppID | User-defined (9 in the feature demo database) | Identity column used for record selection |
| ActionName | VBAuth – Create Contact | Logical action name |
| ClientID | as per Azure Entra App | Application (client) ID |
| TenantID | as per Azure Entra App | Directory (tenant) ID |
| ObjectID | (your Object ID) | Set by PopulateMissingObjectIDs |
| ScopeClaims | Contacts.ReadWrite | Comma-separated Graph scopes |
| Verb | POST | HTTP verb |
| URLPart1 | https://graph.microsoft.com/v1.0/me/contacts | Graph endpoint |
| URLParameter1 | NO VALUE REQUIRED | Not used |
| URLPart2 | NO VALUE REQUIRED | Not used |
| URLParameter2 | NO VALUE REQUIRED | Not used |
| URLPart3 | NO VALUE REQUIRED | Not used |
| WaitForLogin | 60 | Seconds — NB MSXML2 timeout parameters are in milliseconds |
Module: modCreateContact.bas #
Public functions #
CreateContact(strGivenName As String, strSurname As String,
strEmail As String, strBusinessPhone As String,
strMobilePhone As String, strCompanyName As String,
strJobTitle As String, strDepartment As String,
ByRef strMessage As String) As Boolean
Code language: JavaScript (javascript)
Acquires a bearer token for the configured AppID, builds the JSON payload, and POSTs to the Graph /me/contacts endpoint. Returns True on HTTP 201 (Created). Returns False on any other HTTP status or error, with strMessage containing the error detail.
Private functions #
EscapeJsonString(strInput As String) As String
Code language: JavaScript (javascript)
Escapes characters that are special in JSON strings: backslash, double-quote, CR/LF, and tab.
BuildCreateContactPayload(strGivenName, strSurname, strEmail,
strBusinessPhone, strMobilePhone,
strCompanyName, strJobTitle,
strDepartment) As String
Code language: JavaScript (javascript)
Constructs the JSON request body for POST /me/contacts. Fields are only included in the payload if their corresponding parameter is a non-empty string. emailAddresses is formatted as the Graph API array structure with both address and name sub-properties. businessPhones is formatted as the Graph API string array.
Behaviour #
- Creates the contact in the authenticated (signed-in) user’s default contacts folder
- Graph returns HTTP 201 on success with the full contact object in the response body (the response body is not parsed by this module)
- Only
givenNameis required by this module — Graph itself accepts a contact with no fields at all, but a first name is enforced here as a minimum for a useful contact record - A network timeout returns a descriptive error message — timeout duration is controlled by
lngHTTPTimeoutinmodVBAuthGlobalConstants.bas - Special characters in all string fields are escaped automatically before the payload is built
- Requires interactive sign-in — application permissions are not supported
Notes #
- Does not support application permissions
- All fields except
strGivenNameare optional — pass an empty string for any field not required - The contact is created in the user’s default contacts folder — there is no option in this module to specify a target folder
- Admin consent must be granted for
Contacts.ReadWritein the Azure portal before users can authenticate - The Graph API returns HTTP 201 on success, not HTTP 200 — callers must check for 201
VBAuth, developed and maintained by Andrew Richards (The IT Service Ltd) and Peter Bryant (Corylus Business Systems), © 2025–2026. All rights reserved. https://vbauth.com