VBAuth GraphAPI Integration Guide part 1

Adding a Microsoft Graph API Feature to Your Access Application Using VBAuth Part 1 #

Version 1.0 — April 2026 Copyright © 2025–2026 Peter Bryant (Corylus Business Systems) and Andrew Richards (The IT Service Ltd). Part of VBAuth — https://vbauth.com


Prerequisites #

Before starting, confirm the following are in place:

  • VBAuth.dll is installed and registered on your development machine
  • A valid VBAuth licence file is present (VBAuth will not initialise without it)
  • Your Access application (.accdb) exists and opens without errors
  • The lclVBAuthAdmin table is present in your database (supplied with VBAuth)
  • The required VBAuth common code modules are present in your database (see Chapter 7)
  • You have access to the Microsoft Azure portal at https://portal.azure.com
  • You have permission in your organisation’s Azure tenant to create app registrations (or someone who does)

This guide assumes a good working knowledge of Access and VBA development. Azure concepts are explained where needed.


Chapter 1 — How VBAuth Works: The Bearer Token #

Before writing any code, it is worth understanding what VBAuth is doing on your behalf, because it shapes the way every Graph API call is structured.

The problem VBAuth solves #

Microsoft Graph is a REST API. Every call you make to it — whether to send an email, read a calendar, or query a user’s profile — must be authorised. Microsoft uses the OAuth 2.0 protocol for this authorisation. In plain terms, before your VBA code can call an API, it must first prove to Microsoft that:

  1. It is a known, registered application (your Azure app registration)
  2. The signed-in user has consented to the permissions it is requesting
  3. The user’s identity has been verified (which may involve multi-factor authentication)

When all three conditions are satisfied, Microsoft issues an access token — a long, encrypted string. This is the bearer token.

Think of it as a passport. When your VBA code presents the bearer token in the HTTP request header, Microsoft Graph reads it the same way a border officer reads a passport: it confirms who you are, what you are allowed to do, and when the document expires. If the token is valid and covers the permission needed for the API call, the call succeeds. If it is missing, expired, or does not cover the required permission, the call is rejected with HTTP 401 Unauthorized.

What VBAuth does for you #

Obtaining a bearer token the hard way requires implementing the OAuth 2.0 authorisation code flow: opening a browser window, redirecting the user to Microsoft’s login page, capturing the authorisation code from the redirect URI, and exchanging it for a token. This is several hundred lines of non-trivial code.

VBAuth handles all of that. Your VBA code makes a single call:

If Not AcquireBearerToken(strClientID, strTenantID, strScopeRequested) Then
    MsgBox "Authentication failed."
    Exit Function
End If
Code language: PHP (php)

VBAuth opens the Microsoft login window, the user signs in (with MFA if required by your organisation’s policy), and on success the bearer token is stored in the global variable strBearerToken. Your code then includes that token in the Authorization header of every subsequent HTTP call — and Graph accepts it.

AcquireBearerToken handles Base64 decoding of the raw access token internally. The string in strBearerToken is the fully decoded bearer value, ready to use directly as the Authorization header value: http.setRequestHeader “Authorization”, “Bearer ” & strBearerToken You do not need to decode it. For full detail on what VBAuth does with the raw token, see What is VBAuth? — The Authentication Flow at vbauth.com/docs

Tokens are valid for between 60 and 90 minutes, as defined by Microsoft. VBAuth retains the cached token for its full validity period and reuses it silently without re-prompting the user, provided subsequent calls do not require scopes beyond those already covered by the token.

What you are responsible for #

VBAuth handles authentication. You are responsible for:

  • Registering the application in Azure and granting it the correct permissions
  • Storing the Client ID and Tenant ID in the lclVBAuthAdmin table
  • Building the HTTP request (verb, URL, headers, payload)
  • Handling the HTTP response

The chapters that follow walk through each of those steps for the worked example: sending an email via the Graph sendMail endpoint.


Chapter 2 — Choosing Your Graph API Endpoint #

The Microsoft Graph documentation #

The authoritative source for everything Graph is the Microsoft Learn documentation. Start here:

Microsoft Graph API overview: https://learn.microsoft.com/en-us/graph/overview

Full API reference: https://learn.microsoft.com/en-us/graph/api/overview

Every endpoint has its own reference page. For the Send Email worked example used throughout this guide, the page is: https://learn.microsoft.com/en-us/graph/api/user-sendmail

The reference page for each endpoint tells you everything you need: the HTTP verb, the URL, the required permissions, the success status code, and the full request and response body structure. This is where your research begins.

What you need to establish #

For every API endpoint you want to use, you must determine the following before writing any code:

1. The HTTP verb Graph uses standard REST verbs. The most common are:

VerbTypical use
GETRetrieve data (no body required)
POSTCreate a resource or trigger an action
PATCHUpdate an existing resource
DELETERemove a resource

2. The endpoint URL The base URL for all Graph v1.0 calls is https://graph.microsoft.com/v1.0/. The full endpoint URL follows from there. For the Send Email example: https://graph.microsoft.com/v1.0/me/sendMail

3. The required permission scope Every Graph endpoint requires one or more delegated permission scopes. These are listed on the documentation page under Permissions. You need the exact scope name — for example Mail.Send — both for the Azure app registration and for the ScopeClaims column in lclVBAuthAdmin. The two must match exactly.

4. The success HTTP status code Successful Graph calls return a status in the 2xx range, but the specific code varies by endpoint. Always check the documentation for your endpoint — never assume 200. Creating a resource typically returns 201 Created. The sendMail endpoint returns 202 Accepted. Treating the correct code as a failure is a common mistake.

5. The request body structure POST and PATCH requests require a JSON payload. The documentation shows the exact structure, which fields are required, and which are optional.

6. The response body Some calls return a JSON response body containing data you may wish to process or store — for example, a GET that returns a list of items, or a POST that returns the created resource including its ID. Other calls return no body at all — sendMail is one of these. Check the documentation so you know what to expect.

Worked example — Send Email #

From the documentation page at https://learn.microsoft.com/en-us/graph/api/user-sendmail:

ItemValue
VerbPOST
URLhttps://graph.microsoft.com/v1.0/me/sendMail
Required scopeMail.Send
Success status202 Accepted
Request body requiredYes — JSON containing the message
Response bodyNone

The request body structure is:

{
  "message": {
    "subject": "Hello from VBAuth",
    "body": {
      "contentType": "Text",
      "content": "This email was sent via Microsoft Graph."
    },
    "toRecipients": [
      {
        "emailAddress": {
          "address": "recipient@example.com"
        }
      }
    ]
  }
}
Code language: JSON / JSON with Comments (json)

Graph Explorer — optional testing tool #

Once you have identified your endpoint from the documentation, Graph Explorer at https://developer.microsoft.com/en-us/graph/graph-explorer allows you to test calls against a live Microsoft 365 account directly in the browser. This can be useful if your VBA code is not behaving as expected and you want to confirm the endpoint itself is working correctly. It is not a required step.


Chapter 3 — The lclVBAuthAdmin Table #

The lclVBAuthAdmin table is the configuration store for all VBAuth features in your application. Each row represents one Graph API endpoint. VBAuth reads this table at runtime to construct the URL, load the Client ID and Tenant ID, and determine the required scope.

Table structure #

ColumnTypePurpose
AppIDAutoNumberPrimary key — assigned automatically, never set manually
ActionNameTextHuman-readable name, prefixed VBAuth -
ClientIDTextAzure app registration Client ID — entered after creating the Azure registration
TenantIDTextAzure Directory (Tenant) ID — entered after creating the Azure registration
ObjectIDTextAzure app Object ID — used by the VBAuth demo database for programmatic app creation; not required for the manual portal route covered in this guide
ScopeClaimsTextComma-separated Graph permission scope names — must match the Azure app registration exactly
VerbTextHTTP verb: GET, POST, PATCH, or DELETE
URLPart1TextBase URL or first URL segment
URLParameter1TextRuntime URL parameter slot 1 (leave blank if not needed)
URLPart2TextURL segment between parameters (leave blank if not needed)
URLParameter2TextRuntime URL parameter slot 2 (leave blank if not needed)
URLPart3TextURL segment after parameter 2 (leave blank if not needed)
WaitForLoginNumberHTTP call timeout in seconds — multiplied by 1,000 internally for the MSXML2 timeout parameters.’ — applied to all four timeout parameters on each Graph API call. Has a table default; change if your endpoint is slow to respond

About URLPart1 through URLPart3 #

Most simple endpoints have a fixed URL with no runtime parameters. In that case, the entire URL goes in URLPart1 and all other URL columns are left empty.

If your endpoint URL contains a runtime value — for example, https://graph.microsoft.com/v1.0/teams/{teamId}/channels where {teamId} is known only at runtime — then use:

  • URLPart1 = https://graph.microsoft.com/v1.0/teams/
  • URLParameter1 = (your VBA code passes the value at runtime)
  • URLPart2 = /channels

VBAuth assembles the final URL as: URLPart1 + URLParameter1 + URLPart2.

For the Send Email example, the URL is fixed, so only URLPart1 is needed.

Adding the row #

You can add the row in either of two ways — whichever you prefer:

Option A — Run an INSERT query: create a new query in Access, switch to SQL view, paste the following, and run it once:

INSERT INTO lclVBAuthAdmin ( ActionName, ScopeClaims, Verb, URLPart1 )
VALUES ( 'VBAuth - Send Email', 'Mail.Send', 'POST',
         'https://graph.microsoft.com/v1.0/me/sendMail' );
Code language: JavaScript (javascript)

Option B — Type directly into the table: open lclVBAuthAdmin in datasheet view and type or paste the values into a new row.

Important notes:

  • Don’t include AppID as this is an AutoNumber column — Access assigns it automatically
  • ScopeClaims is comma-separated with no spaces when multiple scopes are required, e.g. Mail.Send,Mail.ReadWrite
  • WaitForLogin is not set here — it has a table default
  • ClientID and TenantID are left blank for now — you will add them after creating the Azure app registration in Chapter 4

Once the row has been added — whether by running the query or typing the values directly — note the AppID that Access has assigned. You will use this number throughout the VBA code. In this guide the Send Email AppID is referred to as [n] — substitute your actual value.


Chapter 4 — Creating the Azure App Registration #

Every VBAuth feature requires its own Azure app registration. This is what identifies your application to Microsoft and controls which Graph permissions it is allowed to request.

VBAuth uses delegated permissions exclusively. This means the API call runs as the signed-in user — the user must be present and authenticated, and the call can only do what that user is permitted to do in Microsoft 365. Application permissions (which allow background calls without a signed-in user) are not used.

Step-by-step: Creating the registration #

1. Sign in to the Azure portal Go to https://portal.azure.com and sign in with an account that has permission to create app registrations in your organisation’s tenant.

2. Navigate to App registrations Search for “App registrations” in the top search bar and select it. Click New registration.

3. Name the application Use the same name as your ActionName value, e.g. VBAuth - Send Email. This makes it easy to identify in the portal later.

4. Set the supported account type Select Accounts in this organisational directory only. This restricts the app to users in your tenant.

5. Set the redirect URI Set the platform to Public client/native (mobile & desktop) and enter: http://localhost

This is the redirect URI that VBAuth expects. Do not change it.

6. Click Register Azure creates the registration. You are taken to the Overview page.

7. Copy the IDs — do this now, before navigating away From the Overview page, copy and save:

  • Application (client) ID — this is your ClientID
  • Directory (tenant) ID — this is your TenantID

Open lclVBAuthAdmin and enter both values into the row you created in Chapter 3.

8. Add the delegated permission In the left panel, click API permissions, then Add a permission, then Microsoft Graph, then Delegated permissions.

Search for Mail.Send, tick the checkbox, and click Add permissions. The scope name in ScopeClaims in your lclVBAuthAdmin row must match this value exactly — Mail.Send in both places.

9. Admin consent Granting admin consent is a decision for you and your client to make together. There are two options:

  • Grant consent now — on the API permissions page, click Grant admin consent for [your organisation] and confirm. All users can then use the feature immediately without being prompted.
  • Leave it ungranted — each user will see a Microsoft consent prompt on their first sign-in for this feature, which they can accept themselves.

Neither approach is wrong. The right choice depends on your organisation’s preferences and IT policy.

Your app registration is now ready.


The following chapters are in part 2 of this guide #

Chapter 5 — Writing the VBA Module #

Chapter 6 — Alternative Approach: Create and Send for Message Traceability #

Chapter 7 — Common Code Modules and JSONConverter #

Chapter 8 — Wiring Into Your Form #

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 19, 2026