缩放工作区容量

Python通用API缩放

获取token

import requests

# Power BI Embedded API端点
token_endpoint = 'https://login.partner.microsoftonline.cn/{tenant_id}/oauth2/token'

# 填入您的Azure AD租户ID(tenant ID)、客户端ID(client ID)和客户端机密(client secret)
tenant_id = ''
client_id = ''
client_secret = ''


# 请求访问令牌
data = {
    'grant_type': 'client_credentials',
    'client_id': client_id,
    'client_secret': client_secret,
    'resource': 'https://management.chinacloudapi.cn/'
}

response = requests.post(token_endpoint.format(tenant_id=tenant_id), data=data)
access_token = response.json()
token = access_token['access_token']
token

缩放容量

subscription_id = ""    # 容量订阅id
resource_group = ""  # 资源组名称
capacity_name = ""  # 资源名称
new_size = "A3"
url = f"https://management.chinacloudapi.cn/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.PowerBIDedicated/capacities/{capacity_name}?api-version=2021-01-01"
headers = {
        'Content-Type': 'application/json',
        "Authorization": "Bearer " + token
    }
# Create the request body
body = {
    "sku":{
        "name":new_size,
        "tier":"PBIE_Azure"
    },
    "location":"chinaeast",  # 位置
    "properties": {   # 容量管理员
        "administration": {
            "members": [ "bi@pharmcubebi.partner.onmschina.cn", "pb@pharmcubebi.partner.onmschina.cn" ]
        }
    }
}

response = requests.put(url, json=body,headers=headers)
if response.status_code == 200:
    print("Capacity size updated successfully")
else:
    print(f"Error: {response.text}")

数据工厂