I'm working on integrating Azure Purview with other systems using PowerShell. My goal is to fetch a list of all glossary terms from Azure Purview programmatically using the REST API and PowerShell.
Here's what I've tried so far:
Authentication and Token Retrieval: I have successfully authenticated with Azure using PowerShell and obtained a valid bearer token for Azure Purview using the following script:
# Define Azure Purview details
$resourceGroupName = "ResourceGroupName"
$purviewAccountName = "PurviewAccountName"
# Authenticate and get access token
Connect-AzAccount
$token = Get-AzAccessToken -ResourceUrl "https://purview.azure.net" |
Select-Object -ExpandProperty AccessToken
Attempt to Retrieve Glossary Terms: I attempted to use the following PowerShell script to fetch glossary terms but encountered issues:
# Define Azure Purview API endpoint for glossary terms
$glossaryId = "" #Where to get it?????
$endpoint = "https://$purviewAccountName.purview.azure.com/datamap/api/atlas/v2/glossary/$glossaryId/terms?api-version=2023-09-01&limit=-1&offset=0&sort=ASC"
# Set headers with the access token
$headers = @{
'Authorization' = "Bearer $token"
'Content-Type' = 'application/json'
}
# Make the GET request
try {
$response = Invoke-RestMethod -Uri $endpoint -Headers $headers -Method Get
$response
}
catch {
Write-Error "Failed to retrieve glossary terms. Error: $_"
}
The above script resulted in errors like "Not found" and did not retrieve the expected glossary terms. I've seen examples using other endpoints or parameters like keywords in the API documentation, but I'm unsure of the correct approach for glossary terms.
Could someone provide guidance on the correct PowerShell syntax and parameters to retrieve glossary terms from Azure Purview via the REST API?
Any assistance, examples, or insights into how to structure the API request correctly would be greatly appreciated.
I have one glossary named DemoGlossary
with 2 terms in my Azure Purview account like this:
Initially, run below PowerShell script to get the ID of above glossary:
# Define Azure Purview details
$resourceGroupName = "rgname"
$purviewAccountName = "purviewname"
$token = Get-AzAccessToken -ResourceUrl "https://purview.azure.net" | Select-Object -ExpandProperty Token
$endpoint = "https://$purviewAccountName.purview.azure.com/datamap/api/atlas/v2/glossary?api-version=2023-09-01&limit=1&offset=0&sort=AS"
# Set headers with the access token
$headers = @{
'Authorization' = "Bearer $token"
'Content-Type' = 'application/json'
}
# Make the GET request
try {
$response = Invoke-RestMethod -Uri $endpoint -Headers $headers -Method Get
$response
}
catch {
Write-Error "Failed to retrieve glossary terms. Error: $_"
}
Response:
Now, you can use this GUID value as $glossaryId
and run below script to retrieve the Azure Purview Glossary terms:
# Define Azure Purview details
$resourceGroupName = "rgname"
$purviewAccountName = "purviewname"
$token = Get-AzAccessToken -ResourceUrl "https://purview.azure.net" | Select-Object -ExpandProperty Token
# Define Azure Purview API endpoint for glossary terms
$glossaryId = "706d3acc-9xx9-4xxc-xxxx-xxxxxxxx" #Use GUID from above response
$endpoint = "https://$purviewAccountName.purview.azure.com/datamap/api/atlas/v2/glossary/$glossaryId/terms?api-version=2023-09-01&limit=-1&offset=0&sort=ASC"
$headers = @{
'Authorization' = "Bearer $token"
'Content-Type' = 'application/json'
}
try {
$response = Invoke-RestMethod -Uri $endpoint -Headers $headers -Method Get
$response
}
catch {
Write-Error "Failed to retrieve glossary terms. Error: $_"
}
Response: