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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jburbano
Frequent Visitor

Geting 400 on mutiple api calls to my PBI service

I am building a powershell script to automate publishing.  I have enabled Fiddler and I can catch the 400 bad request, but when I repeat, the same exact request via fiddler...it works.  Is there indeed a timing thing?  I am doing a few API calls, pretty much back to back. I am getting an AAD token, followed by getting the groupid, then the reportid based on the name of the pbix file, to make sure the workspace and report exist and if so, need to be overwritten.  I then publish the pbix, followed by taking ownership of the dataset and setting parameters.  I then am trying to bind the dataset to a gateway using:

 

https://api.powerbi.com/v1.0/myorg/groups/GroupId/datasets/DatasetId/BindToGateway

 

To it I use the following body:

 

{"gatewayObjectId": "GatewayId"}

 

 

First attempt as part of the script I get a:

 

HTTP/1.1 400 Bad Request
Cache-Control: no-store, must-revalidate, no-cache
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
RequestId: 1507f40e-c4d3-4505-b18c-08d756c68599
Date: Tue, 29 Jan 2019 05:10:55 GMT
Content-Length: 189

{"error":{"code":"DMTS_CanNotFindMatchingDatasourceInGatewayError","pbi.error":{"code":"DMTS_CanNotFindMatchingDatasourceInGatewayError","parameters":{},"details":[],"exceptionCulprit":1}}}

 

But using Fiddler's Composer I clone the same EXACT request and get:

 

HTTP/1.1 200 OK
Cache-Control: no-store, must-revalidate, no-cache
Content-Type: application/octet-stream
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
RequestId: b8ce9e60-298d-4054-ae41-78d97c273898
Date: Tue, 29 Jan 2019 05:15:46 GMT
Content-Length: 0

 

Please help. I am actually setting up an Azure DevOps Release pipeline to automate this process for my developers.

 

Update:

 

I have noticed that a 2 second sleep seems to help, but now I am getting this on the update parameters request:

 

HTTP/1.1 429
Cache-Control: no-store, must-revalidate, no-cache
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
RequestId: e63505f6-bf41-4d22-94d8-d883188b4923
Date: Tue, 29 Jan 2019 06:02:01 GMT

7F
{"error":{"code":"ActivityLimitReached","message":"UpdateDatasetParameters on c629a2a9-3932-4ce6-a5f6-1de659406843 throttled"}}
0

 

I think it is self explanatory.

4 REPLIES 4
Jayendran
Solution Sage
Solution Sage

Hi @jburbano / @Anonymous ,

 

I've a working powershell script here  

 

$applicationId = "" # Need to pass the clientid from devops variable 
$clientsec = "" | ConvertTo-SecureString -AsPlainText -Force # Need to pass from devops secret variable 
 
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $clientsec 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "" # Need to pass from devops variable  
 
 
 
$workspacename="PowerBI_CICD_PROD" 
$datasetname="AdventureReports" 
 
 
## user credentials 
 
$username= "sadmin" 
$password= "Password@123" # Need to pass from devops secret variable  
 
 
##Getworksapce 
 
$workspace =Get-PowerBIWorkspace -Name $workspacename 
 
# GetDataSets 
$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json 
 
 
# Get DataSet 
$datasets = $DatasetResponse.value 
 
     foreach($dataset in $datasets){ 
                if($dataset.name -eq $datasetname){ 
                $datasetid= $dataset.id; 
                break; 
                } 
 
            } 
 
## Take Over DataSet 
 
Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.TakeOver" -Method Post 
 
## update data source credentials 
 
$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json 
 
 
$UpdateUserCredential = @{ 
            credentialType ="Basic" 
            basicCredentials = @{             
            username= $username 
            password=$password 
            } 
} | ConvertTo-Json 
 
 
 
Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $UpdateUserCredential | ConvertFrom-Json 
 
 
## update parameter API 
 
   $postParams = @{ 
            updateDetails =@( 
            @{ 
            name="blob" 
            newValue="https://demo.blob.core.windows.net/" 
            } 
            ) 
} | ConvertTo-Json 
 
 
 
Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.UpdateParameters" -Method Post -Body $postParams | ConvertFrom-Json 
 

 

Anonymous
Not applicable

Thank you very much Jayendran, I will try and update you.

Can you tell me which version of Powershell are you using.

Hi @Anonymous ,

 

PSVersion 5.1.17763.1007

Anonymous
Not applicable

Hi jburbano,

 

I am not an expert so I am not able to understand but I am getting the same issue at the Bind Gateway.

Will you be able to share the coode as how you were able to accomplish bind gateways. 

 

I am using service principal account, any help would be appreciated.

 

Thanks

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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