Legacy Dev Forum Posts

 View Only

Sign Up

Access token using the Authorization code for Power BI

  • 1.  Access token using the Authorization code for Power BI

    Posted 06-05-2025 19:20

    Veeraiah_Mannem | 2020-07-10 01:03:18 UTC | #1

    I am trying to generate the access token using the power query(authorization code) but getting the 400 bad request. any help is appreciated.

    let apiUrl = "https://login.mypurecloud.com/oauth/token", body = "{""clientid: ""XXXXX"", ""clientsecret"": ""XXXXXXX"", ""resource"":""https://analysis.windows.net/powerbi/api"", ""granttype"": ""authorizationcode""}", Source = Json.Document(Web.Contents(apiUrl, [Headers = [Accept="application/json"], Content = Text.ToBinary(body)])) in Source

    DataSource.Error: Web.Contents failed to get contents from (400): Bad Request Details:


    anon11147534 | 2020-07-10 11:17:12 UTC | #2

    Please refer to the Authorization Code Documentation to learn how to fully set up the Authorization Code Grant.

    I'm not familiar with Power BI, but after obtaining an authorization code, your code will look more like the following snippet:

    let apiUrl = "https://login.mypurecloud.com/oauth/token",
    body = {
        "grant_type": "authorization_code",
        "code": "<my-authorization-code>",
        "redirect_uri": "<http://example.com/oauth/callback>"
    },
    Source = Json.Document(Web.Contents(apiUrl, [Headers = [Content-Type="application/x-www-form-urlencoded", Authorization="Basic BASE64(<client_id>:<client_secret>)"], Content = Text.ToBinary(body)]))
    ...

    You'll have to refer to the Power BI documentation to learn how to BASE64 encode the <clientid>:<clientsecret> pair.


    system | 2020-08-10 11:17:14 UTC | #3

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 8249