README Create Contact

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 NameRequired Value / ExampleNotes
AppIDUser-defined (9 in the feature demo database)Identity column used for record selection
ActionNameVBAuth – Create ContactLogical action name
ClientIDas per Azure Entra AppApplication (client) ID
TenantIDas per Azure Entra AppDirectory (tenant) ID
ObjectID(your Object ID)Set by PopulateMissingObjectIDs
ScopeClaimsContacts.ReadWriteComma-separated Graph scopes
VerbPOSTHTTP verb
URLPart1https://graph.microsoft.com/v1.0/me/contactsGraph endpoint
URLParameter1NO VALUE REQUIREDNot used
URLPart2NO VALUE REQUIREDNot used
URLParameter2NO VALUE REQUIREDNot used
URLPart3NO VALUE REQUIREDNot used
WaitForLogin60Seconds — 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 givenName is 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 lngHTTPTimeout in modVBAuthGlobalConstants.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 strGivenName are 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.ReadWrite in 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

Updated on April 3, 2026