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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
jvanrossum
New Member

PowerShell Rest API refreshSchedule - Response status code does not indicate success: 400

When I use PowerShell (via DevOps) to call the refreshSchedule operation it fails:
Messages - One or more errors occurred.
Inner Exception - Response status code does not indicate success: 400 (Bad Request).

# Create credentials for Service Principal
$ServicePrincipalCredentials = New-Object System.Management.Automation.PSCredential ($ApplicationId, (convertto-securestring $ClientSecret -asplaintext -force))

# Login to Power BI
Connect-PowerBIServiceAccount -Credential $ServicePrincipalCredentials `
                              -Tenant $TenantId `
                              -Environment Public `
                              -ServicePrincipal 

# Example schedule
[string]$body =  "{""value"":{""times"":[""16:00""],""Enabled"":""true""}}"

# Construct Rest API URL
[string]$Url = "groups/$($WorkspaceId)/datasets/$($dataset.id)/refreshSchedule"

# Call Rest API
Invoke-PowerBIRestMethod -Url $Url -Method Patch -ContentType "application/json" -Body $body

When I print the variables to the screen and copy and paste them in the Try It section of the documentation it always works without errors. Tried serveral ways to construct the body (different messages, different string constructions). Before this Rest API call I have at least a dozen other PBI Rest API call and they all work without errors.... Any suggestions?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Unfortunately is seems that a Service Principal cannot perform this action. You need a Service Account (AAD account) for this.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @jvanrossum ,

 

Please refer to this post:

400 Bad Request Error when embedding report

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the reply, but I'm not sure how that post helps solving my problem. They have the same general error message, but that problem is about embedded.

Anonymous
Not applicable

Unfortunately is seems that a Service Principal cannot perform this action. You need a Service Account (AAD account) for this.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors