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

Power Bi REST API - Groups - 401

Hello all,

 

I have been working on troubleshooting an issue in the power BI service and am pretty stuck.  With a .NET console app, I am able to create and get a dataset as well as add rows to a table in the dataset.  I cannot do an HTTP GET to "https://api.PowerBI.com/v1.0/myorg/groups" without getting a 401 using the same creds to do the work around the dataset.

 

Relevant details:

1) This is a native app

2)  I have tried both the auth token for the app and also using the user context

3)  I am the owner of the app in Azure AD and have admin access to the Power BI site for our org

4)  All permissions have been set for power bi and 3 for AAD:

 permissions.PNG

 

Code:

        {
            string powerBIGroups = "https://api.PowerBI.com/v1.0/myorg/groups";
            HttpWebRequest request = System.Net.WebRequest.Create(powerBIGroups) as System.Net.HttpWebRequest;
            request.KeepAlive = true;
            request.Method = "GET";

            //Add token to the request header
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token));

            string datasetId = string.Empty;
            //Get HttpWebResponse from GET request
            using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
            {
                //Get StreamReader that holds the response stream
                using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
                {
                    string responseContent = reader.ReadToEnd();

                    var results = JsonConvert.DeserializeObject<dynamic>(responseContent);

                    //Get the first id
                    datasetId = results["value"][0]["id"];

                    Console.WriteLine(String.Format("Dataset ID: {0}", datasetId));
                    Console.ReadLine();

                    return datasetId;
                }
            }

        }

The error is thrown at "using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)":

 

An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (401) Unauthorized. occurred

 

Any ideas?  I would like to get the dataset into a group so I can share with others in the org.

 

Eric

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-jiascu-msft
Microsoft

Re: Power Bi REST API - Groups - 401

Hi @ES_CW,

 

1. Did you click the "Grant permissions" after select the permission items?

Power_Bi_REST_API_Groups_401

2. Did you have a step that would retrieve the token before this step?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Microsoft v-jiascu-msft
Microsoft

Re: Power Bi REST API - Groups - 401

Hi @ES_CW,

 

1. Did you click the "Grant permissions" after select the permission items?

Power_Bi_REST_API_Groups_401

2. Did you have a step that would retrieve the token before this step?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

ES_CW
Regular Visitor

Re: Power Bi REST API - Groups - 401

Thanks Dale.  I had thought I had the access, as it shows all access granted, but I am not an admin for the Azure AD instance, and as it turns out, even though I didn't have access granted, it showed that I did.  That was my downfall.

 

So - your fix above worked.  I just had a false positive in the dashboard, and I made the assumption that it was granted.  At any rate, it is now.  

 

Thanks!

Eric

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors