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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Datasource status by ID REST API call fails with Bad Request 400 error

I am working with the REST API. Per the documentation, we can query datasource status by ID. https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/getdatasourcestatusbyid It appears the URL is identical to querying a datasource by ID, with "/status" appended to the end.

 

But I always get a 400 "Bad request" error.

 

A GET with the appropriate header to this URL to query the datasource works:

https://api.powerbi.com/v1.0/myorg/Gateways/742dbe90-2a61-453e-90e7-123456789abc/Datasources/38ec9ca...

 

A GET with the same header to this URL to query the datasource status fails:

https://api.powerbi.com/v1.0/myorg/Gateways/742dbe90-2a61-453e-90e7-123456789abc/Datasources/38ec9ca...

 

If I try it with "/status2" the error is 404 "Not found". So "/status" is there, but either it is broken, or there is an error in the docs on how to use it, or I am doing something wrong.

 

Any ideas?

 

Thanks,

Tim Curwick

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

With a hint from Kay Unkroth, I realized the API returns more detailed error information in the response body. When using Invoke-RestMethod, the response body requires a little work to get at.

 

try { Invoke-RestMethod -Uri $Uri -Headers $Headers }
catch { ([System.IO.StreamReader]$_.Exception.Response.GetResponseStream()).ReadToEnd() }

 

With that, I was able to see that I'm getting a timeout error. I'm opening a ticket with Microsoft to find out why.

 

Thanks,

Tim Curwick

View solution in original post

Anonymous
Not applicable

WABD - Working as (badly) designed.

 

It turns out the API returns an http error to tell you the queried datasource status is "error". (We have an on-going issue putting many of our datasources in an error status, which is why I'm writing something to monitor the status.) Which means you need complicated code to tell the difference between an actual http error and status information. And additional complicated code to get the additional details about the error status, because PowerShell commands don't allow for the possibility that an API would successfully return data, but label the response with an error code.

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

With a hint from Kay Unkroth, I realized the API returns more detailed error information in the response body. When using Invoke-RestMethod, the response body requires a little work to get at.

 

try { Invoke-RestMethod -Uri $Uri -Headers $Headers }
catch { ([System.IO.StreamReader]$_.Exception.Response.GetResponseStream()).ReadToEnd() }

 

With that, I was able to see that I'm getting a timeout error. I'm opening a ticket with Microsoft to find out why.

 

Thanks,

Tim Curwick

Anonymous
Not applicable

WABD - Working as (badly) designed.

 

It turns out the API returns an http error to tell you the queried datasource status is "error". (We have an on-going issue putting many of our datasources in an error status, which is why I'm writing something to monitor the status.) Which means you need complicated code to tell the difference between an actual http error and status information. And additional complicated code to get the additional details about the error status, because PowerShell commands don't allow for the possibility that an API would successfully return data, but label the response with an error code.

 

 

Anonymous
Not applicable

Hi,

 

Not sure if this is still useful but if the datasource is OK then a 200 response is returned with no data. So lets say you do $ds = Invoke-Restmethod ...

If $ds -eq $null {

     $result = "OK"

}

In case the datasource is in error you can do this:

Try {

$ds = Invoke-Restmethod ...

$datum = New-Object –TypeName PSObject
$datum | Add-Member @{DataSourceID=$datasource_id} -PassThru
$datum | Add-Member @{DataSourceStatus="OK"} -PassThru
$datum

}

catch {

$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$ErrResp = $streamReader.ReadToEnd() | ConvertFrom-Json
$streamReader.Close()
$datum = New-Object –TypeName PSObject
$datum | Add-Member @{DataSourceID=$datasource_id} -PassThru
$datum | Add-Member @{DataSourceStatus=$ErrResp.error.code} -PassThru

$datum

}

}

 

Hope this helps

Anonymous
Not applicable

liljath,

 

Thank you. I am doing something similar.

 

BTW, while it still appears in a lot of sample scripts, this is actualy a PS v1 coding pattern:

 

$datum = New-Object –TypeName PSObject
$datum | Add-Member @{DataSourceID=$datasource_id} -PassThru
$datum | Add-Member @{DataSourceStatus="OK"} -PassThru
$datum

 

Try this instead:

[pscustomobject]@{
    DataSourceID = $datasource_id
    DataSourceStatus = $ErrResp.error.code }

 

Thanks,

Tim Curwick

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.