Forum Discussion

shaw's avatar
shaw
Frequent Visitor
6 years ago
Solved

400 Bad Request Error when embedding report

I am trying to embed the Power BI report into 3rd party web app. Trying to test this in Java Code Sample. I am able to authenticate, and in fact, get the response with the correct reportId, groupId. 

When I call the API https:// api.powerbi.com/v1.0/myorg/GenerateToken, it goes to catch and throws out Error: 400 Bad Request. 

I tried the same thing on postman too, likewise, I am getting the embedded URL too, please see the response below.

 

{
"@odata.context": "http://wabi-us-north-central-redirect.analysis.windows.net/v1.0/myorg/groups/xxxxxxxxxxxxxxxxxxxxxxxx/$metadata#reports/$entity",
"id": "xxxxxxxxxxxxxxxxxxxxx",
"reportType": "PowerBIReport",
"name": "My Embed Dashboard",
"webUrl": "https://app.powerbi.com/groups/xxxxxxxxxxxxxxxxxxxxx/reports/xxxxxxxxxxxxxxxxxxxx",
"embedUrl": "https://app.powerbi.com/reportEmbed?reportId=xxxxxxxxxxxxx&groupId=xxxxxxxxx=2&config=xxxxxxxx",
"isFromPbix": true,
"isOwnedByMe": true,
"datasetId": "xxxxxxxxxx"
}

 

if I access the embedUrl through the browser, I end with 400 bad request error as I get from the code debugging. 

I tried the solution proposed in this discussion, tried this on code as well as on the postman. But no luck with that. Still, the embedUrl loads nothing with the browser's console error:

DevTools failed to load SourceMap: Could not load content for https://app.powerbi.com/13.0.13035.244/scripts/interact.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE


SOME INFO TO TROUBLESHOOT THIS ISSUE:

Auth Method: Service Principal
Azure App Type: Web

Is Service Principal added to the security group and security group under the admin tenant settings on powerbi service : Yes

Is Service Principal added to the workspace: Yes

Is API permission provided: delegated full access to all datasets, tenant, groups, reports, workspace, capacity etc., 

Is Scope defined: consent is added for "admins and users"

Authorized client applications: Added the clientid 

 

Any help is appreciated. 


Thanks

Shawkath 

 

  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi shaw 

    If you are using the 'App owns data' type of embedding + using the Service Principal to generate embedding tokens, then this Identity section of the token request should contain details of the 'user' used for Row Level Security purposes.

    Are you reports/dashboards using Row Level Security?
    If so... your identity section should look like this...

    "identities": [
        {
          "username": "[email protected]",
          "roles": [
            "My PBI Role Name"
          ],
          "datasets": [
            "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
          ]
        }
      ]

     

    Username can be any value - you are effectively impersonating this person - and this has no link to any account in your Azure tenant or Power BI access list.

    Roles should contain any Power BI (RLS) roles that you have defined inside your data model. Note that you should not supply roles here if you are not using RLS - and dont supply roles that dont exist in your model. Again, this is not a role that belongs to your Service Principal account or any other Power BI account type (admin/member/viewer) etc..

    Hope this helps,
    Cheers - Matt

8 Replies

  • shaw's avatar
    shaw
    Frequent Visitor

    UPDATE: While testing the APIs, we identified the error "dataset or the user does not exist, set identify to the dataset". 

    After inserting the identities node to the requestHeader (as per the JSON below)

     

     

    {
      "datasets": [
        {
          "id": "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
        }
      ],
      "reports": [
        {
          "id": "b2e49b01-2356-4456-bfb9-3f4c2bc4ddbd"
        }
      ],
      "identities": [
        {
          "username": "<AZURE APP ID GOES HERE>",
          "roles": [
            "Admin"
          ],
          "datasets": [
            "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
          ]
        }
      ]
    }

     

     


    The original issue I posted here is now resolved. So we are able to see the dashboard displayed on our web application. 

    Another issue still exists: Although the service principal is an admin and as an admin, this service principal has the full access to the workspace, the data is not loading on the embedded report. Only the report's layout is loading but not the actual dashboard. 

    So we tried to add identities for the report level with the role name to the above-mentioned JSON. Still, we haven't got any luck so far. I also checked to have the following permissions set on the azure app. 

     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi shaw 

      If you are using the 'App owns data' type of embedding + using the Service Principal to generate embedding tokens, then this Identity section of the token request should contain details of the 'user' used for Row Level Security purposes.

      Are you reports/dashboards using Row Level Security?
      If so... your identity section should look like this...

      "identities": [
          {
            "username": "[email protected]",
            "roles": [
              "My PBI Role Name"
            ],
            "datasets": [
              "cfafbeb1-8037-4d0c-896e-a46fb27ff229"
            ]
          }
        ]

       

      Username can be any value - you are effectively impersonating this person - and this has no link to any account in your Azure tenant or Power BI access list.

      Roles should contain any Power BI (RLS) roles that you have defined inside your data model. Note that you should not supply roles here if you are not using RLS - and dont supply roles that dont exist in your model. Again, this is not a role that belongs to your Service Principal account or any other Power BI account type (admin/member/viewer) etc..

      Hope this helps,
      Cheers - Matt

      • shaw's avatar
        shaw
        Frequent Visitor

        Hi Anonymous 

         

        Appreciate your help here. 

         

        I tried to pass on the JSON to the request header as you suggested with the role I am using. My scenario is that the user from a school would login, based on their schoolid I am performing RLS. Role I have set is 'school' which I have mentioned correctly. I am not sure how to pass on the rule. I couldn't find any help on the community or through the official reference. 

        From the UI, once the user authenticates in our web app, we will pass on the schoolid to the ajax call. 

         

        {
          "datasets": [
            {
              "id": "18727ad-680b-4248-b571-xxxxxxxxxxxx"
            }
          ],
          "reports": [
            {
              "id": "xxxxxx7-31e9-4a28-8317-047df26b908c"
            }
          ],
          "identities": [
            {
              "username": "[email protected]",
              "roles": [
                "school"
              ],
              "datasets": [
                "18727ad-680b-4248-b571-xxxxxxxxxxxx"
              ]
            }
          ]
        }

         My assumption is that I will be passing the rule through the report.setFilter() from the AJAX call through the javascript. 

        However, on both the Java & Javascript end, what would go in the perfect scenario?