Error 401 Power BI API RRS feed

  • Question

  • I'm making a workaround to pick up the power BI upgrade history but I'm getting 401 return, I've already released all permissions for the application. I can generate the token normally, but when I try to get the groups I get "Unauthorized access", do you have any idea what I need to verify?

    my code

    Public Function getToken() As String
            Dim objs As RootObject
            Dim cliente = New RestClient("https://login.microsoftonline.com/00000000/oauth2/token")
            Dim req = New RestRequest()
            req.Method = Method.POST
            req.AddHeader("Content-Type", "application/x-www-form-urlencoded")
            req.AddParameter("grant_type", "client_credentials", ParameterType.GetOrPost)
            req.AddParameter("client_id", "0000000", ParameterType.GetOrPost)
            req.AddParameter("client_secret", "000000", ParameterType.GetOrPost)
            req.AddParameter("resource", "https://analysis.windows.net/powerbi/api", ParameterType.GetOrPost)
            Dim resposta = cliente.Execute(req)
            Dim content = resposta.Content.ToString
            objs = JsonConvert.DeserializeObject(Of RootObject)(content.ToString)
            Dim token = objs.access_token
            Return (token.ToString)
        End Function
    Private Function getData(ByVal url As String) As String
            Dim powerBIApiUrl As String = url
            Dim token As String = getToken()
            Dim request As HttpWebRequest = TryCast(System.Net.WebRequest.Create(powerBIApiUrl), System.Net.HttpWebRequest)
            request.KeepAlive = True
            request.Method = "GET"
            request.ContentLength = 0
            request.ContentType = "application/json; charset=utf-8"
            request.Headers.Add("Authorization", String.Format("Bearer {0}", token))
            Using httpResponse As HttpWebResponse = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
                Using reader As StreamReader = New System.IO.StreamReader(httpResponse.GetResponseStream())
                    Dim responseContent As String = reader.ReadToEnd()
                    Return responseContent.ToString
                End Using
            End Using
        End Function

    Fabiano Carvalho

    Tuesday, August 28, 2018 12:35 PM

All replies

  • Hi Faabiianooc,

    This forum discusses and asks questions about extending and integrating with Visual Studio, since your issue is more related to Power BI, I would suggest that you could post your issue in Power BI forum for suitable support.


    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 29, 2018 3:03 AM