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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jamir
Frequent Visitor

How to get EmbedToken Generated using PostMan ? HTTP Error 400. The request hostname is invalid.

1. I was able to genrate Accesstoken using : (Works in postman)

 POST - https://login.microsoftonline.com/{{tenant_id}}/oauth2/token

 Header:

 Content-Type application/x-www-form-urlencoded

 Body:

 grant_type: client_credentials

 client_secret: {{client_secret}}

 client_id: {{client_id}}

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

(works fine)

 

2. Get EmbedToken (Does not work in postman):

    I could get the EmbedToken using link below.

    https://learn.microsoft.com/en-us/rest/api/power-bi/embed-token/datasets-generate-token-in-group

    (for our prototype, we will not want to use above step)

 

  Using Postman I have tried many different scenarios, it all fails

 

  POST - https://api.powerbi.com/v1.0/myorg/groups/{{groupId}}/reports/{{reportId}}/GenerateToken

  Header:

Authorization: Bearer {{temp_access_token}}

Host: <calculated when request is sent>

Content-Type: application/json

  Body:

{
"accessLevel": "View",
"allowSaveAs": "false"
}

 

  Result:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML>

<HEAD>
<TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>

<BODY>
<h2>Bad Request - Invalid Hostname</h2>
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>
</BODY>

</HTML>
 
3. Get Embed URL (Does not work in postman)
     This works:
      (for our prototype, we will not want to use above step)
 
Using Postman

POST -https://api.powerbi.com/v1.0/myorg/groups/{{groupId}}/reports

  Header:

Authorization: Bearer {{temp_access_token}}

 

Error:

{
"error": {
"code": "PowerBINotAuthorizedException",
"pbi.error": {
"code": "PowerBINotAuthorizedException",
"parameters": {},
"details": [],
"exceptionCulprit": 1
}
}
}
 
1 ACCEPTED SOLUTION
Jamir
Frequent Visitor

Finally, I made it work.. Here are all the details:

(I beleive my problem was with setting up Service Principal properly)

 

1. Access Token: POST

Header

Jamir_0-1664062616546.png

Body

Jamir_1-1664062650858.png

 

2. Embed Token: POST

Header

Jamir_2-1664062696666.png

 

Body

Jamir_3-1664062724198.png

 

3. EmbedReportURL: GET

     

Jamir_4-1664062752331.png

 

View solution in original post

3 REPLIES 3
Jamir
Frequent Visitor

Finally, I made it work.. Here are all the details:

(I beleive my problem was with setting up Service Principal properly)

 

1. Access Token: POST

Header

Jamir_0-1664062616546.png

Body

Jamir_1-1664062650858.png

 

2. Embed Token: POST

Header

Jamir_2-1664062696666.png

 

Body

Jamir_3-1664062724198.png

 

3. EmbedReportURL: GET

     

Jamir_4-1664062752331.png

 

Jamir
Frequent Visitor

hello @Anonymous 

 

Appreciate your response.

 

I did both, it still does not work, I get HTTP Error 400, The request hostname is invalid. Error.

 

Jamir_0-1663951959886.png

 

Anonymous
Not applicable

Hello @Jamir ,

I had the same issue and adding these headers worked 

2022-09-23_11h16_59.png

 

URLhttps://api.powerbi.com/v1.0/myorg/groups/d...c5/reports/da9.....3/GenerateToken

Body: 

{
"accessLevel""View",
"allowSaveAs""false"
}
If it still doesn't work, click on run it in Embed Token - Reports GenerateTokenInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Lear... add your group id, report id and copy paste the URl. It worked!

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.