1
votes

Summary : I am working on embedding Power BI reports in a ISV application and when i try to call api endpoint to get embedding details of the report it responds with 400 Bad Request . I am directly calling Power BI APIs without use of SDK as microsoft hasn't officially released PowerBI SDK for Java based application . Also , for debugging I used another .net application which uses PowerBI SDK to make the same API call against same workspace and it works without issues.

All other API endpoints like 'list all workspaces','get workspace details',' list all dashboards' in a workspace ' and even 'list all reports in workspace' respond as requested without issues, but the API endpoint listed here :

Power BI get report embedding details using 'workspace_id' and 'report_id'

responds with 400 Bad request with seemingly right credentials and request.

Interfacing Application Context :

  1. The ISV application is built on Spring boot framework(Java) and Angular 2 framework .
  2. Currently,I couldn't find official Microsoft Power BI SDK for Java based application , because of which i am directly referencing APIs from the Power BI API reference doc
  3. ISV application has all necessary permissions to access the APIs listed here : https://docs.microsoft.com/en-us/power-bi/developer/power-bi-permissions
  4. The application is able to generate token,make authenticated request and get response from power bi for all other api endpoints which are used in the application .

Issue and Debugging

Debugging :

  1. This is the request that PowerBI .NET SDK makes and which works against get report API :

GET https://api.powerbi.com/v1.0/myorg/groups/d864b33b-74dd-4683-9cfd-91c712039147/reports/d618f04d-0b9d-483b-8f9c-cb1210d14595 HTTP/1.1

Authorization: Bearer auth-token

User-Agent: FxVersion/4.7.2117.0 Windows_7_Enterprise/6.1.7601 Microsoft.PowerBI.Api.V2.PowerBIClient/2.0.2.17225

Host: api.powerbi.com

  1. This is the request that my application makes directly referencing API endpoint which returns 400 :

GET https://api.powerbi.com/v1.0/myorg/groups/d864b33b-74dd-4683-9cfd-91c712039147/reports/d618f04d-0b9d-483b-8f9c-cb1210d14595 HTTP/1.1

cache-control: no-cache

Postman-Token: some-token

Authorization: Bearer auth-token

User-Agent: PostmanRuntime/7.1.1

Accept: /

Host: api.powerbi.com

1
Microsoft provides APIs for C# and Javascript. Perhaps you could try same calls via Javascript and see what happens. Two things that stand out: 1) User agent differences (shouldn't matter, but who knows) and 2) Postman-Token: some-token. PowerBI.Api simply wraps Http calls, you should be able to debug and capture details and then try to build the same request in Postman. If nothing helps, you can route via Fidler, to inspect differences.Sherlock
Thanks for the response sherlock , i did the exact same things that you suggested in your responseAmit Bhandari
1. Since i was getting 400 from my application i used fiddler to inspect the differences and construct the api call on Postman where i got the same result . The header information posted in the question is a PowerBI SDK call and other is a Postman constructed call respectively ,both are sniffed results out of fiddler .Also , User agent is nothing but which application is making the request first is Application using powerBI SDK and second is Postman.Amit Bhandari
Postman-Token is a token that Postman adds to any api call which it makes you can disable it in postman settings . I did try both ways and it did not matter.Amit Bhandari
In Postman, are you using Bearer Token Authorization?Sherlock

1 Answers

3
votes

This is due to Accept HTTP header. Microsoft`s REST Method does not support it. Try:

curl -XGET 
"https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}" -i -H 
"Authorization: Bearer {token}" -H "Accept:"

-H "Accept:" will disable this HTTP header. (By default curl sends Accept: * / *)