Forum Discussion
Power BI REST API using postman - generate embed token.
- 8 years ago
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-data/m-p/296611#M8734 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.
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}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 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-data/m-p/296611#M8734 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.
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}
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?
Above solution only mentioned using Master User account to authenticate and get access token, in the request body we need provide username and password, Request URL is https://login.microsoftonline.com/common/oauth2/token. Actually we can use either https://login.microsoftonline.com/common/oauth2/token or https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token for master user.
Note: we need replace "{tenantID}" with cx tenant ID.
Furthermore, we can also use Service Principal to authenticate and get access token: the request URL can only be https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token
In the request body, we need set grant_type as client_credentials, and provide client_id and client_secret. After Create an Azure AD app, we will have Application ID(client_id) and secret.
- Burhan_Jiru3 years agoFrequent Visitor
Hi jerry,
I am trying the same in postman. but with this token I am not able to generate embed token in postman.
sharing response which I am getting when generating access token. can please confirm this is the correct response and you are getting the same.
If this is the correct response can you please guide me on how to generate embed token in Postman?
thank you
- arthurviana2 years agoNew Member
Hello, I am getting the same error. Did you manage to make this work yet with client credentials?
- Anonymous2 years agoNot applicable
I'm facing some troubles in to replicate what has been done here.
I had already register the app on Azure AD and create the workspace in Power BI as mention here: Get started with Power BI Embedded - Power BI | Microsoft Learn
But when I use your steps to get access token by Postman, I receive that the hostname is not correct:
Can somebody help me please?
- zmorlan3 years agoFrequent Visitor
what is cx tenant ID
- Jerry-Tang3 years agoMicrosoft Employee