Azure Purview - Search By Glossary Terms using Atlas API
Azure Purview's support to Atlas API has led a way to create custom reporting applications based on our need. In this blog we'll see how we can leverage the API to create a report based on assigned glossary terms.
Find the Enterprise Application Id for Purview:
Generate an OAuth token:
url = "https://login.microsoftonline.com/{{Directory (Tenant) ID}}/oauth2/token"
body={
"grant_type": "client_credentials",
"client_id": "{{Service Client Id}}",
"client_secret": "{{Service Client Credential}}",
"resource": "{{Enterprise Application Id for Purview}}"
}
response = requests.post(url=url, data=body)
token = response.json()
expires_on = int (token['expires_on'])
access_token = token['access_token']
Fetch all Glossary Terms:
url = "https://{{purview atlas api endpoint}}/api/atlas/v2/glossary"
header = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } response = requests.get(url=url, headers=header) response_status = response.status_code data = response.json() terms = data[0]['terms']
Select required Terms (optional):
searchTerms = {}
termGuid = ""
for term in terms:
displayText = term['displayText']
if displayText.startswith({{searchTerm}}):
termGuid = term['termGuid']
searchTerms [termGuid] = displayText
Get all associated Entities (optional):
url = 'https://{{purview atlas api endpoint}}/api/atlas/v2/entity/guid/' + {{termGuid}}
header = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
response = requests.get(url=url, headers=header)
response_status = response.status_code
data = response.json()
assets = data['entity']['relationshipAttributes']['assignedEntities']
assetsList = []
for asset in assets:
assetsList.append (asset['guid'])
Comments
Post a Comment