0

I'm trying to refresh Azure Analysys tables using rest api (https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-async-refresh) and python. I've created a user with server admin role and an azure ad application with owner role, but rest api seams to be rejecting the access tokens. How can I assign the necessary rights or what I do incorrect. I'm trying to access Analysis Services for example like this:

import adal

tenant_id = '...'
authentication_endpoint = f'https://login.windows.net/{tenant_id}'
resource  = 'https://westeurope.asazure.windows.net/'
client_id = '...'
client_secret = '...'
# get an Azure access token using the adal library
context = adal.AuthenticationContext(authentication_endpoint)
token_response = context.acquire_token_with_client_credentials(resource, client_id, client_secret)

access_token = token_response.get('accessToken')
print(access_token)

#####################################################

import json
import requests

location = 'westeurope'
server_name = '...'
model = '...'

url = f'https://{location}.asazure.windows.net/servers/{server_name}/models/{model}/refreshes'
table = '...'
objects = [ dict(table=table) ]
data = dict(
    type = 'Full',
    # CommitMode = 'transactional',
    # MaxParallelism = 2,
    RetryCount = 2,
    Objects = objects,
)
headers = {
  'Content-Type': 'application/json',
  'Authorization': f'Bearer {access_token}',
}

response = requests.post(url=url, headers=headers, data = json.dumps(data))
print(response.text)
print(response.status_code)

The response is like this:

{"code":"Unauthorized","subCode":0,"message":"An internal error occurred.","timeStamp":"...","httpStatusCode":400,"details":[{"code":"RootActivityId","message":"..."},{"code":"Param1","message":"asazure://asazureweu3-westeurope.asazure.windows.net/..."}]}
400
1

To call the refreshes API the service principal must have admin permissions in SSAS. This is not accomplished through the Azure portal but through SQL Server Management Studio as described here.

Once the service principal is created, its application ID can be assigned permissions in the Azure Analysis Services server or model roles using the following syntax. The example below adds a service principal to the server administrators group in SSMS.

app:<app guid>@<tenant guid>

server admin in SSMS

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.