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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DivakarKrishnan
Helper II
Helper II

Power BI Data refresh using REST API Power shell commands

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

 

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

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.

View solution in original post

2 REPLIES 2
v-xicai
Community Support
Community Support

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.

v-xicai
Community Support
Community Support

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.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.