Forum Discussion

pangelino's avatar
pangelino
Regular Visitor
8 years ago
Solved

Unauthorized response getting reports through groups endpoint of API

I'm using the Power API REST API to first retrieve groups that the logged in user has access to, and then to retrieve reports within those groups.  I can successfully retrieve reports through the https://api.powerbi.com/v1.0/myorg/reports endpoint, but if I make the request through the https://api.powerbi.com/v1.0/myorg/groups/{group_id}/reports endpoint with any of the retrieved group id's, I get a 401 - Unauthorized response.  I am sending the access token as an authorization header using the "Bearer {token}" format, the same as when I successfully retrieve reports independent of the group id.  Can anyone suggest what the problem is here?  Thanks in advance!

  • pangelino's avatar
    pangelino
    8 years ago

    Eric, in preparing to reply to you I finally discovered the problem.  In my C# code I was sending the HTTP request like this:

     

    HttpWebRequest request = CreatePowerBiApiRequest("groups/{groupId}/reports", accessToken);

    What I realized today is that I forgot the $ at the beginning of the string so that the string interpolation would occur.  It should have been like this:

    HttpWebRequest request = CreatePowerBiApiRequest($"groups/{groupId}/reports", accessToken);

    So the request was just statically sending the string "{groupId}" in the request instead of substituting in the actual group ID value.  Totally my bad! :smileyembarrassed:

     

    Thanks for your help!

5 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    pangelino wrote:

    I'm using the Power API REST API to first retrieve groups that the logged in user has access to, and then to retrieve reports within those groups.  I can successfully retrieve reports through the https://api.powerbi.com/v1.0/myorg/reports endpoint, but if I make the request through the https://api.powerbi.com/v1.0/myorg/groups/{group_id}/reports endpoint with any of the retrieved group id's, I get a 401 - Unauthorized response.  I am sending the access token as an authorization header using the "Bearer {token}" format, the same as when I successfully retrieve reports independent of the group id.  Can anyone suggest what the problem is here?  Thanks in advance!


    pangelino

    Is the registered app with sufficient permissions? You can check the permission in Azure portal->Active Directory->App registrations. The delegated perssions count shall be 14.

     

    Is your account a member of the workspace group?

    • pangelino's avatar
      pangelino
      Regular Visitor

      Thanks for your reply Eric_Zhang.  I should have mentioned that when I log into powerbi.com with the same account that I use to test the application, I can navigate through "Workspaces" (groups in the API), and can see and execute reports within them.  My application seems to see all the same groups, but is unauthorized to request reports through the groups/{group_id}/reports endpoint.

       

      I have added all the permissions you noted below, even including one Application Permissions that you do not call out.  My Azure permissions on the app registration now look like this, but I still get the same 401 Unauthoorized response:

       

      Any other suggestions?

    • pangelino's avatar
      pangelino
      Regular Visitor

      Eric_ZhangI'm still stuck on this.  Would you recommend that I open a ticket with technical support on this?

      • Eric_Zhang's avatar
        Eric_Zhang
        Microsoft Employee

        pangelino

        Is the groupid correct? Can you send the accesstoken in your case to me through a private message?