Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Dear Team,
I am trying to schedule the power BI dataset refresh using REST API Power shell below code, but when I am executing this code in Powershell ISE I am getting below error message. I have doiwnloaded all power shell modules and my role is Power BI admin in Azure. Please assist to solve this issue.
Error Message: Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
Power Shell Script:
$groupID = "Deleting it" # the ID of the group that hosts the dataset. Use "me" if this is your My Workspace
$datasetID = "Deleting it" # the ID of the dataset that hosts the dataset
# AAD Client ID
# To get this, go to the following page and follow the steps to provision an app
# https://dev.powerbi.com/apps
# To get the sample to work, ensure that you have the following fields:
# App Type: Native app
# Redirect URL: urn:ietf:wg:oauth:2.0:oob
# Level of access: all dataset APIs
$clientId = "Deleting it"
# End Parameters =======================================
# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceAppIdURI = "https://analysis.windows.net/powerbi/api"
$authority = "https://login.microsoftonline.com/common/oauth2/authorize";
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
return $authResult
}
# Get the auth token from AAD
$token = GetAuthToken
# Building Rest API header with authorization token
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token.CreateAuthorizationHeader()
}
# properly format groups path
$groupsPath = ""
if ($groupID -eq "me") {
$groupsPath = "myorg"
} else {
$groupsPath = "myorg/groups/$groupID"
}
# Refresh the dataset
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST –Verbose
# Check the refresh history
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET –Verbose
Solved! Go to Solution.
Hi @DivakarKrishnan ,
You may check if it is caused by firewall, or upgrade the Power Shell . There are some similar cases you may refer to :
Asp.net error: The remote server returned an error: (403) Forbidden
"The remote server returned an error: (403) Forbidden." error when calling from REST s
The remote server returned an error: (403) Forbidden
Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @DivakarKrishnan ,
If you still have this issue for Power BI, you'd better create a support ticket in Power BI Support , Scroll down and click "CREATE SUPPORT TICKET", or go to Issue forum to get further help.
Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @DivakarKrishnan ,
You may check if it is caused by firewall, or upgrade the Power Shell . There are some similar cases you may refer to :
Asp.net error: The remote server returned an error: (403) Forbidden
"The remote server returned an error: (403) Forbidden." error when calling from REST s
The remote server returned an error: (403) Forbidden
Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 73 | |
| 59 | |
| 27 | |
| 23 | |
| 20 |