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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors