cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
insoldev Regular Visitor
Regular Visitor

Power BI REST API using postman - generate embed token.

Hello - currently working through trying to get an embed token using the Power BI rest api. I am following the guidance as on this page. https://msdn.microsoft.com/en-us/library/mt784614.aspx.

 

ultimately, I am trying to achieve the outcome of using javascript to host a Power BI report in the new model as per https://community.powerbi.com/t5/Developer/Embedding-without-hard-coding-master-credentials-app-owns... as per @Eric_Zhang suggestion.

 

I am not getting an embed token - I am simply getting this response. Clearly I've missed something - I am using my client secret as the bearer token.

 

postman body.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator Eric_Zhang
Moderator

Re: Power BI REST API using postman - generate embed token.


@insoldev wrote:

Hello - currently working through trying to get an embed token using the Power BI rest api. I am following the guidance as on this page. https://msdn.microsoft.com/en-us/library/mt784614.aspx.

 

ultimately, I am trying to achieve the outcome of using javascript to host a Power BI report in the new model as per https://community.powerbi.com/t5/Developer/Embedding-without-hard-coding-master-credentials-app-owns... as per @Eric_Zhang suggestion.

 

I am not getting an embed token - I am simply getting this response. Clearly I've missed something - I am using my client secret as the bearer token.

 

 


@insoldev

The bearer token requires an access token, not the client secret. You need to follow this link to register a Native app rather than a server-side web app for Power BI Embedded cases and grant sufficient permissions.

 

Then to get the access token, you can call the POST API in POSTMAN as

POST /common/oauth2/token HTTP/1.1
Host: login.windows.net
Cache-Control: no-cache 
Content-Type: application/x-www-form-urlencoded

client_id={client id}&grant_type=password&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&username={your power bi account}&password={your Power BI password}

Capture.PNG

 

With the above access_token, you can call the GenerateToken API.

 

By the way, using POSTMAN is recommended for testing/debug purpose, what would you like in your case?

7 REPLIES 7
Moderator Eric_Zhang
Moderator

Re: Power BI REST API using postman - generate embed token.


@insoldev wrote:

Hello - currently working through trying to get an embed token using the Power BI rest api. I am following the guidance as on this page. https://msdn.microsoft.com/en-us/library/mt784614.aspx.

 

ultimately, I am trying to achieve the outcome of using javascript to host a Power BI report in the new model as per https://community.powerbi.com/t5/Developer/Embedding-without-hard-coding-master-credentials-app-owns... as per @Eric_Zhang suggestion.

 

I am not getting an embed token - I am simply getting this response. Clearly I've missed something - I am using my client secret as the bearer token.

 

 


@insoldev

The bearer token requires an access token, not the client secret. You need to follow this link to register a Native app rather than a server-side web app for Power BI Embedded cases and grant sufficient permissions.

 

Then to get the access token, you can call the POST API in POSTMAN as

POST /common/oauth2/token HTTP/1.1
Host: login.windows.net
Cache-Control: no-cache 
Content-Type: application/x-www-form-urlencoded

client_id={client id}&grant_type=password&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&username={your power bi account}&password={your Power BI password}

Capture.PNG

 

With the above access_token, you can call the GenerateToken API.

 

By the way, using POSTMAN is recommended for testing/debug purpose, what would you like in your case?

insoldev Regular Visitor
Regular Visitor

Re: Power BI REST API using postman - generate embed token.

Thanks for your response - I'm just testing to make sure I have the components working correctly.

Yikun Frequent Visitor
Frequent Visitor

Re: Power BI REST API using postman - generate embed token.

First I would like to say sorry that I don't have an exact solution about this but I feel like that Whatever I will suggest here it would be helpful or it will work.

 

Just go through the article REST API in Power BI where all things are described in the wonderful and easy way. Diagrams and video are also available in this article which will help to learn in a more easier way.

 

 

Yikun Frequent Visitor
Frequent Visitor

Re: Power BI REST API using postman - generate embed token.

First I would like to say sorry that I don't have an exact solution about this but I feel like that Whatever I will suggest here it would be helpful or it will work.

 

Just go through the article REST API in Power BI where all things are described in the wonderful and easy way. Diagrams and video are also available in this article which will help to learn in a more easier way.

 

Hope it Helps Smiley Happy

insoldev Regular Visitor
Regular Visitor

Re: Power BI REST API using postman - generate embed token.

@Yikun, that isn't even close to relevant - I'm talking about using the Power BI API in an embedded application, not using an API as a data source in Power BI.

insoldev Regular Visitor
Regular Visitor

Re: Power BI REST API using postman - generate embed token.

Hi @Eric_Zhang - I wanted to thank you for your contribution. This worked for me and gave me a really good steer. I have used Azure Functions apps to provide the server side functionality.

alainp Frequent Visitor
Frequent Visitor

Re: Power BI REST API using postman - generate embed token.

I am getting this response from Postman:

"error": "invalid_grant", "error_description": "AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: c3c862a5-440b-43ba-a105-7efea28b2800\r\nCorrelation ID: 7df5b009-805a-4738-8c81-b9eca778054a\r\nTimestamp: 2018-10-18 20:14:11Z", "error_codes": [ 70002, 50126 ],

 

but I know my login/pw are good because if I use the same credentials/client_id with the Python library PyPowerBi (https://github.com/cmberryau/pypowerbi)

 

I can connect and make API calls, so the problem has to be with the Postman setup:

 

POST: https://login.microsoftonline.com/common/oauth2/token

 

BODY:

grant_typeSmiley Tongueassword

client_id:{{client_id}}

resource:https://analysis.windows.net/powerbi/api

scopeSmiley Surprisedpenid

username:{{username}}

password:{{password}}