Reply
Frequent Visitor
Posts: 3
Registered: ‎11-20-2018
Accepted Solution

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

 

 


Accepted Solutions
Frequent Visitor
Posts: 3
Registered: ‎11-20-2018

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

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

Frequent Visitor
Posts: 3
Registered: ‎11-20-2018

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

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


All Replies
Frequent Visitor
Posts: 3
Registered: ‎11-20-2018

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

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

Frequent Visitor
Posts: 3
Registered: ‎11-20-2018

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

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.