Forum Discussion

lese's avatar
lese
New Member
7 years ago

Resume and suspend powerbi capacity programmatically

Developing Power bi embedded web-app written in django (python). I retrive workspace, dashboards and report successfully, I also get capacity informations against azure portal , all this by using access token retrived in the following way (using adal python module):

def azure_auth():
    context = adal.AuthenticationContext(
        settings.PBI_AUTHORITY,
        validate_authority=True,
        api_version=None)

    token_response = context.acquire_token_with_username_password(
        settings.PBI_RESOURCE,
        settings.PBI_USERNAME,
        settings.PBI_PASSWORD,
        settings.PBI_CLIENTID
    )

    aad_token = token_response['accessToken']

    headers = {'Authorization': 'Bearer ' + aad_token}

    return headers
subsequently i use the retrieved token to make the various requests and they al work fine, the following works fine too, witch it is similar (from a permission point view) to the requests that i'm unable to perform (resume / suspend capacity):
def get_capacities(headers):
    capacities_request = requests.get(
        "https://api.powerbi.com/v1.0/myorg/capacities", headers=headers)

    print("HTTP response:" + str(capacities_request))

    obj = json.loads(capacities_request.text)
    print("capacities: \n" + str(obj))
But resuming capacity as following fail with a 401 Unauthorized http error code: 
def resume_pbi_capacity(headers):
  response = requests.post('https://management.azure.com/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.PowerBIDedicated/capacities/CAPACITY_NAME/resume?api-version=2017-10-01', headers)
  print(response)
I may use a different method to retrieve the token? 
 
reading here I have corrected the permissions (Access control (IAM)) into Azure portal to allowing the user that the application use to perform suspend /resume operations, but it does not seems to be enough
 
 
How to retrive token to perform suspend / resume capacity operations? 
No RepliesBe the first to reply