I am trying to run below code and getting AtlasException:
{“requestId”:”36fb4fc3-bc6b-4583-b6a1-faac6a5723b4″,”errorCode”:”ATLAS-403-00-001″,”errorMessage”:”5133fd99-b486-4723-ac91-c8acc375a4ed is not authorized to perform create entity: type=test file”}
Note: I have access to only specific collection in Purview. I cannot create entities in root collection.
from azure.identity import ClientSecretCredential
from pyapacheatlas.auth import ServicePrincipalAuthentication
from pyapacheatlas.core import AtlasClient, collections
from pyapacheatlas.core import AtlasEntity, RelationshipTypeDef
import requests
import os
import json
import pandas as pd
import pydicom
# Azure AD credentials
tenant_id = "xxxxxxxxxxxxxxxxxxxx"
client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Purview account details
purview_account_name = "account-name"
collection_name = "abcde"
# Authenticate using AAD
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
auth = ServicePrincipalAuthentication(
tenant_id=tenant_id,
client_id=client_id,
client_secret=client_secret
)
# Create an Atlas client
client = AtlasClient(
endpoint_url=f"https://{purview_account_name}.purview.azure.com/catalog/api/atlas/v2",
authentication=auth
)
entity_up = AtlasEntity(
name="API_TEST_NEW",
typeName='test file',
qualified_name="TESTING_API_NEW",
attributes={
"description": "A sample entity with custom attributes",
"businessAttributes": {
"businessAttribute1": "Business Value 1",
"businessAttribute2": "Business Value 2"
},
"customAttributes": {
"customKey1": "Custom Value 1",
"customKey2": "Custom Value 2"
}
},
collectionId = 'abcde',
domainId = 'account-name',
contacts = {
"Expert": [
{
"id": "xxxxxxxxxxxxxxxxx",
"info": "Example Expert Info"
}
],
"Owner": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"info": "Example Owner Info"
}
]
},
)
client.upload_entities(entity_up)
How to create entities in specific collection(Not in root) using AtlasClient? I am able to create it through PurviewClient but getting issue with AtlasClient.
Naveen Chandraiah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
errorMessage”:”5133fd99-b486-4723-ac91-c8acc375a4ed is not authorized to perform create entity:
The client you are using is not having required permissions to create entity in specific collection, that may be the reason to get above error. According to the MS document The client should below roles to perform actions on collections:
- Collection admins
- Data source admins
- Data curators
- Data readers
For each role, select the Edit role assignments button and select the role you want to add the service principal to. Or select the Add button next to each role, and add the service principal by searching its name or Client ID as shown below:
Then you will be able to create entity in particular collections. For more information, you can refer below:
-
https://learn.microsoft.com/en-us/answers/questions/2087651/getting-unauthorized-error-while-creating-entity-p
-
https://learn.microsoft.com/en-us/answers/questions/1233528/unauthorized-not-authorized-to-create-processes-in