Good news: You can easily leverage the Microsoft Graph API + Power Query (M Language) to read Purview metadata!
β What You'll Learn
- βοΈ Register an Azure AD App to access Purview via Graph
- βοΈ Grant the necessary permissions
- βοΈ Generate an access token in Power Query
- βοΈ Query Purview using Microsoft Graph API from Power Query
- βοΈ Load Purview data into Power BI or Excel
π£ Step 1: Register an App in Azure AD
- βοΈ Go to Azure Portal > Azure Active Directory > App registrations > New registration
- βοΈ Name it:
PurviewGraphReader - βοΈ Set Redirect URI as
https://localhost(for testing) - βοΈ Click Register
π£ Step 2: Assign API Permissions
- βοΈ Go to API permissions > Add a permission
- βοΈ Choose Microsoft Graph
- βοΈ Select Application permissions
- βοΈ Search for and add:
Catalog.Read.All(needed for Purview Catalog API) - βοΈ Click Grant admin consent
π£ Step 3: Create a Client Secret
- βοΈ Go to Certificates & Secrets > New client secret
- βοΈ Provide a description and set expiry
- βοΈ Save the generated secret value securely
π£ Step 4: Collect Important Details
- βοΈ Directory (Tenant) ID
- βοΈ Application (Client) ID
- βοΈ Client Secret
- βοΈ Purview Account Name & Endpoint (e.g.,
https://your-account.purview.azure.com)
π£ Step 5: Sample Power Query Code
let
// Parameters - replace with your values
tenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
clientSecret = "YOUR_CLIENT_SECRET",
purviewAccountName = "your-purview-account",
// Get Token URL
tokenUrl = "https://login.microsoftonline.com/" & tenantId & "/oauth2/v2.0/token",
// Request Access Token
tokenResponse = Json.Document(Web.Contents(tokenUrl,
[
Content = Text.ToBinary("client_id=" & clientId &
"&scope=https%3A%2F%2Fpurview.azure.net%2F.default" &
"&client_secret=" & clientSecret &
"&grant_type=client_credentials"),
Headers = [#"Content-Type"="application/x-www-form-urlencoded"]
])),
access_token = tokenResponse[access_token],
// Call Purview Catalog API
purviewUrl = "https://" & purviewAccountName & ".purview.azure.com/catalog/api/search/query?api-version=2021-05-01-preview",
// Example Body - Adjust for your use case
body = "{""keywords"":""*""}",
purviewResponse = Json.Document(Web.Contents(purviewUrl,
[
Headers = [
#"Authorization" = "Bearer " & access_token,
#"Content-Type"="application/json"
],
Content=Text.ToBinary(body),
Method="POST"
])),
// Convert API response to a table
purviewData = purviewResponse[results],
purviewTable = Table.FromList(purviewData, Splitter.SplitByNothing(), {"Record"})
in
purviewTable
Explanation:
- βοΈ Authenticates to Azure AD using OAuth2
- βοΈ Queries Purview Catalog API
- βοΈ Retrieves catalog search results
- βοΈ Adaptable for custom queries (e.g., glossary, assets)
π£ Step 6: Load into Power BI or Excel
You can now easily load this data inside:
- βοΈ Power BI Desktop
- βοΈ Excel Power Query Editor
Point to notes:
- βοΈ Purview API is not yet part of core Microsoft Graph but follows a similar structure
- βοΈ
Catalog.Read.Allpermission is read-only - βοΈ Expand records into columns easily inside Power Query Editor
Common Errors:
| Error | Reason |
|---|---|
| Invalid client secret | Check if the client secret expired or is wrong |
| Insufficient privileges | Make sure you granted admin consent |
| 401 Unauthorized | Wrong tenant ID, client ID, or missing scope |
Tips:
- βοΈ Change the
bodyparameter for custom searches - βοΈ Extend this to read glossary, classification, or asset data
- βοΈ Use Power Query parameters to make the code reusable