PowerBI Server上提供的计划刷新功能很方便,但也有一定的限制,比如刷新次数最大为每天48次,而这还是需要Premium许可的情况下才拥有的刷新次数,如果只是Pro许可,那么刷新次数就只有每天8次。此外,计划刷新时是刷新整个数据集的,此时可能只是部分表的数据有变化,但仍然刷新了所有表,增加了不必要的刷新时间。虽然有这些限制,但一般来说,计划刷新功能已经足够使用。
但如果想突破最大刷新次数或只刷新数据集中的部分表,那么可以通过REST API的方式来进行刷新,使用REST API的增强型刷新可以只刷新数据集中的部分表,并且可以突破每天48次的刷新次数,但这需要Premium许可才行,Pro许可的刷新次数仍然被限制在每天8次。
另外,当对数据的实时性有一定要求时,也经常使用REST API来进行刷新,比如该常见场景:当数据库的数据更新后就同步最新数据到PowerBI报表上。由于数据库的数据更新可能具有不确定性,此时采用计划刷新将使PowerBI报表上的数据存在延时,因此在该场景下通常是把刷新报表的操作嵌入到ETL的某个环节中,从而需要使用到REST API。
调用REST API刷新报表
PowerBI的REST API有很多,这里只介绍刷新报表所用到的API,若对其它API感兴趣,可以自行浏览官方文档:了解 Power BI REST API。
API接口:
Url:https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshes # Global
Url:https://api.powerbi.cn/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshes # 21Vianet
Method:POST
Request Headers: {Authorization:访问令牌, Content-Type:application/json}
1、默认刷新整个数据集:
Request Body = {}
2、增强型刷新,可刷新部分表
Request Body =
{
"type": "full",
"commitMode": "transactional",
"maxParallelism": 2,
"retryCount": 2,
"objects": [
{"table": "tableName1"},
{"table": "tableName2"}
]
}
参数说明:
1. 访问令牌
关于获取访问令牌的具体步骤与原理,请参考我的另一篇文章:Azure应用注册与访问令牌获取,并从该文章末尾处复制给出的现成代码,然后填写相关参数即可。注意:需要给Azure应用授予PowerBI Services的Dataset.ReadWrite.All权限。
2. groupId与datasetId
groupId与datasetId为需要刷新的报表所关联的数据集所在的工作区ID与数据集ID,一般来说报表与数据集都是位于同一工作区的,但如果报表与数据集分别位于不同的工作区时就需要注意,使用的是数据集所在的工作区的ID。
可以打开报表所关联的数据集,然后从浏览器上方地址栏处获取这两个ID,具体如下图所示:
3. Request Body
该参数为调用API时的请求体参数,通过它可以更细致的控制刷新时的行为,比如指定只刷新某几个表,以及刷新失败是否有邮件通知,失败后重新尝试多少次等等。如果采用默认的刷新策略,那么将该参数设置为:{}
即可。如果想要刷新某几个表,那么可以设置为:
{
"type": "full",
"commitMode": "transactional",
"maxParallelism": 2,
"retryCount": 2,
"objects": [
{"table": "tableName1"},
{"table": "tableName2"}
...
]
}
以上只是简单的举例,关于Request Body的更多信息与说明,请见官方文档。
当所有参数都获取到后,就可以调用该REST API刷新报表了。以Python为例,调用REST API刷新报表的代码如下:
def refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY={}):
# refresh pbi dataset and return refresh status
if ENVIRONMENT_TYPE.lower() not in ['global','21vianet']:
return 404
apiRootUrl = 'https://api.powerbi.com/v1.0/myorg/groups/' if ENVIRONMENT_TYPE.lower()=="global" else 'https://api.powerbi.cn/v1.0/myorg/groups/'
refresh_api = apiRootUrl + WORKSPACE_ID + '/datasets/' + DATASET_ID + '/refreshes'
response = requests.post(refresh_api, headers={'authorization':TOKEN},json=REQUEST_BODY)
return response.status_code
# Refreash Entire Dataset:
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID)
# Refreash some tables in Dataset:
REQUEST_BODY = {
"type": "full",
"commitMode": "transactional",
"maxParallelism": 2,
"retryCount": 2,
"objects": [
{"table": "tableName1"},
{"table": "tableName2"}
]
}
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY)
注意事项
1、服务主体API访问
在获取访问令牌时,若选择使用服务主体模式,则必须在PowerBI Service的门户管理中打开服务主体API访问的功能,若只使用主用户模式,则不用打开该功能。
2、工作区的访问权限
获取访问令牌时无论是使用主用户模式还是服务主体模式,都需要给相应的主用户或服务主体授予工作区的访问权限。具体的权限级别视情况而定,比如刷新报表就需要参与者或以上权限,如果是共享报表那就需要成员或以上权限,因此建议授予成员或管理员权限是比较好的。
给工作区添加权限时,如果添加的是服务主体,则使用Azure应用的名称进行搜索并添加;如果添加的是主用户,则使用主用户的名称或邮箱进行搜索并添加。
完整的实现代码
为方便使用,下面给出从获取访问令牌到调用REST API刷新PowerBI报表的完整实现代码,有多个版本,可自选其一,均支持国际版与世纪互联两个环境,且可以选择使用主用户或服务主体模式,只需要填写相应参数即可。
PowerQuery OAuth2.0 :
let
// Define a function to acquire access token.
get_access_token = (ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE,AUTHORITY_URL) =>
/*
Author: 夕枫
Function Description:
Generates and returns Access token
Returns:
string: Access token
Below params if don't need to use, pls use blank string to replace, such as: ""
ENVIRONMENT_TYPE : Can be set to 'Global' or '21Vianet'
AUTHENTICATION_MODE : Can be set to 'MasterUser' or 'ServicePrincipal'
CLIENT_ID : Client Id (Application Id) of the AAD app
TENANT_ID : Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET : Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
USER_ACCOUNT : Master user email address. Required only for MasterUser authentication mode.
USER_PASSWORD : Master user email password. Required only for MasterUser authentication mode.
SCOPE_BASE : Scope Base of AAD app. Required when the REST API dosn't is PowerBI REST API.
AUTHORITY_URL : URL used for initiating authorization request, can set to blank string, will use default URL. Required when the default URL fail.
*/
try
if not List.Contains({"global","21vianet"},Text.Lower(ENVIRONMENT_TYPE)) then
error "Error! Pls check the input of ENVIRONMENT_TYPE."
else let
SCOPE_BASE = if SCOPE_BASE<>"" then SCOPE_BASE else if Text.Lower(ENVIRONMENT_TYPE)="global" then "https://analysis.windows.net/powerbi/api/.default" else "https://analysis.chinacloudapi.cn/powerbi/api/.default",
AUTHORITY_URL = if AUTHORITY_URL<>"" then SCOPE_BASE else if Text.Lower(ENVIRONMENT_TYPE)="global" then "https://login.microsoftonline.com/organizations/oauth2/v2.0/token" else "https://login.chinacloudapi.cn/organizations/oauth2/v2.0/token",
RESPONSE =
if Text.Lower(AUTHENTICATION_MODE) = "masteruser" then
Web.Contents(
AUTHORITY_URL,
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content =
Text.ToBinary(
Text.Format(
"client_id=#{0}&scope=#{1}&username=#{2}&password=#{3}&grant_type=password",
{CLIENT_ID,SCOPE_BASE,USER_ACCOUNT,USER_PASSWORD}
)
)
]
)
else if Text.Lower(AUTHENTICATION_MODE) = "serviceprincipal" then
Web.Contents(
Text.Replace(AUTHORITY_URL,"organizations",TENANT_ID),
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content =
Text.ToBinary(
Text.Format(
"client_id=#{0}&scope=#{1}&client_secret=#{2}&grant_type=client_credentials",
{CLIENT_ID,SCOPE_BASE,CLIENT_SECRET}
)
)
]
)
else
error "Error! Pls check the input of AUTHENTICATION_MODE."
in "Bearer " & Json.Document(RESPONSE)[access_token]
otherwise error "Error retrieving Access token, pls check the input params.",
// define a function to refresh pbi dataset and return refresh status
refresh_pbi_dataset = (ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,optional REQUEST_BODY) =>
if not List.Contains({"global","21vianet"},Text.Lower(ENVIRONMENT_TYPE)) then
error "Error! Pls check the input of ENVIRONMENT_TYPE."
else let
apiRootUrl = if Text.Lower(ENVIRONMENT_TYPE)="global" then "https://api.powerbi.com/v1.0/myorg/groups/" else "https://api.powerbi.cn/v1.0/myorg/groups/",
refresh_api = apiRootUrl & WORKSPACE_ID & "/datasets/" & DATASET_ID & "/refreshes",
request_body = if REQUEST_BODY=null then "{}" else REQUEST_BODY,
response =
Web.Contents(
refresh_api,
[
Headers =
[
#"Content-Type"="application/json",
authorization=TOKEN
],
Content = Text.ToBinary(request_body)
]
)
in try if Text.FromBinary(response)="" then 200 else 400 otherwise 401,
// ------------------------------------------------config setting-----------------------------------------------------
// Can be set to 'Global' or '21Vianet'
ENVIRONMENT_TYPE = "Global",
// Can be set to 'MasterUser' or 'ServicePrincipal'
AUTHENTICATION_MODE = "ServicePrincipal",
// Client Id (Application Id) of the AAD app
CLIENT_ID = "Input CLIENT_ID here.",
// Below params if don't need to use, pls use blank string to replace, such as: ''
// Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
TENANT_ID = "Input TENANT_ID here.",
// Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET = "Input CLIENT_SECRET here.",
// Master user email address. Required only for MasterUser authentication mode.
USER_ACCOUNT = "",
// Master user email password. Required only for MasterUser authentication mode.
USER_PASSWORD = "",
// If Use PowerBI REST API, the below parma can set to blank string. Otherwise, pls input the available url of other REST API.
SCOPE_BASE = "",
// The below parma can set to blank string to use default AUTHORITY_URL. If the default setting fail, pls input the available url.
AUTHORITY_URL = "",
// ------------------------------------------------config setting end-------------------------------------------------
TOKEN = get_access_token(ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE,AUTHORITY_URL),
// -------------------------------------------Call REST API by above TOKEN--------------------------------------------
WORKSPACE_ID = "Input WORKSPACE_ID here.",
DATASET_ID = "Input DATASET_ID here.",
// Refreash Entire Dataset:
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID)
/*
// Refreash some tables in Dataset:
REQUEST_BODY =
[
#"type"="full",
commitMode="transactional",
maxParallelism=2,
retryCount=2,
objects=
{
[table="tableName1"],
[table="tableName2"]
}
],
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,Text.FromBinary(Json.FromValue(REQUEST_BODY)))
*/
in
result
Python OAuth2.0 :
import requests
import os
def get_access_token(ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE='',AUTHORITY_URL=''):
'''
Author: 夕枫
Function Description:
Generates and returns Access token
Returns:
string: Access token
Below params if don't need to use, pls use blank string to replace, such as: ''
ENVIRONMENT_TYPE : Can be set to 'Global' or '21Vianet'
AUTHENTICATION_MODE : Can be set to 'MasterUser' or 'ServicePrincipal'
CLIENT_ID : Client Id (Application Id) of the AAD app
TENANT_ID : Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET : Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
USER_ACCOUNT : Master user email address. Required only for MasterUser authentication mode.
USER_PASSWORD : Master user email password. Required only for MasterUser authentication mode.
SCOPE_BASE : Scope Base of AAD app. Required when the REST API dosn't is PowerBI REST API.
AUTHORITY_URL : URL used for initiating authorization request, can set to blank string, will use default URL. Required when the default URL fail.
'''
if ENVIRONMENT_TYPE.lower() not in ['global','21vianet']:
return 'Error! Pls check the input of ENVIRONMENT_TYPE.'
if SCOPE_BASE=='':
SCOPE_BASE = 'https://analysis.windows.net/powerbi/api/.default' if ENVIRONMENT_TYPE.lower()=="global" else 'https://analysis.chinacloudapi.cn/powerbi/api/.default'
if AUTHORITY_URL=='':
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token' if ENVIRONMENT_TYPE.lower()=="global" else 'https://login.chinacloudapi.cn/organizations/oauth2/v2.0/token'
try:
if AUTHENTICATION_MODE.lower() == 'masteruser':
response = requests.post(
AUTHORITY_URL,
headers={'Content-Type':'application/x-www-form-urlencoded'},
data={
'client_id':CLIENT_ID,
'scope':SCOPE_BASE,
'username':USER_ACCOUNT,
'password':USER_PASSWORD,
'grant_type':'password'
}
)
elif AUTHENTICATION_MODE.lower() == 'serviceprincipal':
response = requests.post(
AUTHORITY_URL.replace('organizations', TENANT_ID),
headers={'Content-Type':'application/x-www-form-urlencoded'},
data={
'client_id':CLIENT_ID,
'scope':SCOPE_BASE,
'client_secret':CLIENT_SECRET,
'grant_type':'client_credentials'
}
)
else:
return 'Error! Pls check the input of AUTHENTICATION_MODE.'
return 'Bearer ' + response.json()['access_token']
except Exception as ex:
return 'Error retrieving Access token : ' + str(ex)
def refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY={}):
# refresh pbi dataset and return refresh status
if ENVIRONMENT_TYPE.lower() not in ['global','21vianet']:
return 404
apiRootUrl = 'https://api.powerbi.com/v1.0/myorg/groups/' if ENVIRONMENT_TYPE.lower()=="global" else 'https://api.powerbi.cn/v1.0/myorg/groups/'
refresh_api = apiRootUrl + WORKSPACE_ID + '/datasets/' + DATASET_ID + '/refreshes'
response = requests.post(refresh_api, headers={'authorization':TOKEN},json=REQUEST_BODY)
return response.status_code
if __name__ == '__main__':
# ----------------------------------------------------------config setting----------------------------------------------------------------
# Can be set to 'Global' or '21Vianet'
ENVIRONMENT_TYPE = 'Global'
# Can be set to 'MasterUser' or 'ServicePrincipal'
AUTHENTICATION_MODE = 'ServicePrincipal'
# Client Id (Application Id) of the AAD app
CLIENT_ID = 'Input CLIENT_ID here.'
# Below params if don't need to use, pls use blank string to replace, such as: ''
# Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
TENANT_ID = 'Input TENANT_ID here.'
# Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET = 'Input CLIENT_SECRET here.'
# Master user email address. Required only for MasterUser authentication mode.
USER_ACCOUNT = ''
# Master user email password. Required only for MasterUser authentication mode.
USER_PASSWORD = ''
# If Use PowerBI REST API, the below parma can set to blank string. Otherwise, pls input the available url of other REST API.
SCOPE_BASE = ''
# The below parma can set to blank string to use default AUTHORITY_URL. If the default setting fail, pls input the available url.
AUTHORITY_URL = ''
# ---------------------------------------------------------config setting end---------------------------------------------------------------
TOKEN = get_access_token(ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE,AUTHORITY_URL)
WORKSPACE_ID = 'Input WORKSPACE_ID here.'
DATASET_ID = 'Input DATASET_ID here.'
if 'Bearer' in TOKEN:
# Refreash Entire Dataset:
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID)
'''
# Refreash some tables in Dataset:
REQUEST_BODY = {
"type": "full",
"commitMode": "transactional",
"maxParallelism": 2,
"retryCount": 2,
"objects": [
{"table": "tableName1"},
{"table": "tableName2"}
]
}
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY)
'''
if result in [200,202]:
print('Refresh Successful!')
else:
print(f'Error! Status_Code:{result}')
else:
print(TOKEN)
os.system('pause')
Python MSAL :
import msal
import requests
import os
def get_access_token(ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE='',AUTHORITY_URL=''):
'''
Author: 夕枫
Function Description:
Generates and returns Access token
Returns:
string: Access token
Below params if don't need to use, pls use blank string to replace, such as: ''
ENVIRONMENT_TYPE : Can be set to 'Global' or '21Vianet'
AUTHENTICATION_MODE : Can be set to 'MasterUser' or 'ServicePrincipal'
CLIENT_ID : Client Id (Application Id) of the AAD app
TENANT_ID : Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET : Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
USER_ACCOUNT : Master user email address. Required only for MasterUser authentication mode.
USER_PASSWORD : Master user email password. Required only for MasterUser authentication mode.
SCOPE_BASE : Scope Base of AAD app. Required when the REST API dosn't is PowerBI REST API.
AUTHORITY_URL : URL used for initiating authorization request, can set to blank string, will use default URL. Required when the default URL fail.
'''
if ENVIRONMENT_TYPE.lower() not in ['global','21vianet']:
return 'Error! Pls check the input of ENVIRONMENT_TYPE.'
if SCOPE_BASE=='':
SCOPE_BASE = ['https://analysis.windows.net/powerbi/api/.default'] if ENVIRONMENT_TYPE.lower()=="global" else ['https://analysis.chinacloudapi.cn/powerbi/api/.default']
if AUTHORITY_URL=='':
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations' if ENVIRONMENT_TYPE.lower()=="global" else 'https://login.chinacloudapi.cn/organizations'
try:
response = None
if AUTHENTICATION_MODE.lower() == 'masteruser':
# Create a public client to authorize the app with the AAD app
clientapp = msal.PublicClientApplication(CLIENT_ID, authority=AUTHORITY_URL)
accounts = clientapp.get_accounts(username=USER_ACCOUNT)
if accounts:
# Retrieve Access token from user cache if available
response = clientapp.acquire_token_silent(SCOPE_BASE, account=accounts[0])
if not response:
# Make a client call if Access token is not available in cache
response = clientapp.acquire_token_by_username_password(USER_ACCOUNT, USER_PASSWORD, scopes=SCOPE_BASE)
elif AUTHENTICATION_MODE.lower() == 'serviceprincipal':
authority = AUTHORITY_URL.replace('organizations', TENANT_ID)
clientapp = msal.ConfidentialClientApplication(CLIENT_ID, client_credential=CLIENT_SECRET, authority=authority)
# Make a client call if Access token is not available in cache
response = clientapp.acquire_token_for_client(scopes=SCOPE_BASE)
else:
return 'Error! Pls check the input of AUTHENTICATION_MODE.'
return 'Bearer ' + response['access_token']
except Exception as ex:
return 'Error retrieving Access token : ' + str(ex)
def refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY={}):
# refresh pbi dataset and return refresh status
if ENVIRONMENT_TYPE.lower() not in ['global','21vianet']:
return 404
apiRootUrl = 'https://api.powerbi.com/v1.0/myorg/groups/' if ENVIRONMENT_TYPE.lower()=="global" else 'https://api.powerbi.cn/v1.0/myorg/groups/'
refresh_api = apiRootUrl + WORKSPACE_ID + '/datasets/' + DATASET_ID + '/refreshes'
response = requests.post(refresh_api, headers={'authorization':TOKEN},json=REQUEST_BODY)
return response.status_code
if __name__ == '__main__':
# ----------------------------------------------------------config setting----------------------------------------------------------------
# Can be set to 'Global' or '21Vianet'
ENVIRONMENT_TYPE = 'Global'
# Can be set to 'MasterUser' or 'ServicePrincipal'
AUTHENTICATION_MODE = 'ServicePrincipal'
# Client Id (Application Id) of the AAD app
CLIENT_ID = 'Input CLIENT_ID here.'
# Below params if don't need to use, pls use blank string to replace, such as: ''
# Id of the Azure tenant in which AAD app and Power BI report is hosted. Required only for ServicePrincipal authentication mode.
TENANT_ID = 'Input TENANT_ID here.'
# Client Secret (App Secret) of the AAD app. Required only for ServicePrincipal authentication mode.
CLIENT_SECRET = 'Input CLIENT_SECRET here.'
# Master user email address. Required only for MasterUser authentication mode.
USER_ACCOUNT = ''
# Master user email password. Required only for MasterUser authentication mode.
USER_PASSWORD = ''
# If Use PowerBI REST API, the below parma can set to blank string. Otherwise, pls input the available url of other REST API. And the input scopes should be a list, tuple, or set.
SCOPE_BASE = ''
# The below parma can set to blank string to use default AUTHORITY_URL. If the default setting fail, pls input the available url.
AUTHORITY_URL = ''
# ---------------------------------------------------------config setting end---------------------------------------------------------------
TOKEN = get_access_token(ENVIRONMENT_TYPE,AUTHENTICATION_MODE,TENANT_ID,CLIENT_ID,CLIENT_SECRET,USER_ACCOUNT,USER_PASSWORD,SCOPE_BASE,AUTHORITY_URL)
WORKSPACE_ID = 'Input WORKSPACE_ID here.'
DATASET_ID = 'Input DATASET_ID here.'
if 'Bearer' in TOKEN:
# Refreash Entire Dataset:
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID)
'''
# Refreash some tables in Dataset:
REQUEST_BODY = {
"type": "full",
"commitMode": "transactional",
"maxParallelism": 2,
"retryCount": 2,
"objects": [
{"table": "tableName1"},
{"table": "tableName2"}
]
}
result = refresh_pbi_dataset(ENVIRONMENT_TYPE,TOKEN,WORKSPACE_ID,DATASET_ID,REQUEST_BODY)
'''
if result in [200,202]:
print('Refresh Successful!')
else:
print(f'Error! Status_Code:{result}')
else:
print(TOKEN)
os.system('pause')