Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lese
New Member

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? 
0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.