Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Connecting to API

Hi experts,

 

I am trying to connect PowerBI to API. I a doing this for the first time, so not sure how to proceed. Looking for your guidance.

 

This is the URL I am trying to connect.

https://login.microsoftonline.com/ea80952e-a476-42d4-aaf4-5457852b0f7e/oauth2/token

 

I have the following details:

1. client_id = 'c*****a'
2. client_secret = 'r********e'
3. resource= 'f********9'

4. grant_type=client_credentials

 

I am trying to provide the details as

Getting the below error.

 

 

 

Getting the response from Postman.

Please advise.

 

Thanks.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Anonymous Great, the idea was only to pass the credential in the body and not in header as you were doing earlier. 

13 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks ghumarepratik21. for the response. I have the client_secret which should be the API key, i believe. Anyways, I will check on this line.

       

      Thanks.

      • Anonymous's avatar
        Anonymous
        Not applicable

        HI Anonymous,

        AFAIK, these types of parameters(e.g. client id, secret) will be transformed into a binary string and attached to the httprequest 'content' part instead of directly sending the original string from the httprequest header.

        let
            url = "https://login.microsoftonline.com/xxxxxxx/oauth2/token",
            GetJson =
                Web.Contents(
                    url,
                    [
                        Headers = [
                            Accept = "application/json",
                            ContentType = "application/x-www-form-urlencoded"
                        ],
                        Content =
                            Text.ToBinary(
                                "grant_type=client_credentials&
                                client_id=xxxxxxx&
                                client_secret=xxxxxxx&
                                scope=xxxxxx"
                            )
                    ]
                ),
            token = Json.Document(GetJson)[access_token],
            Result =
                Web.Contents(
                    "https://xxxxx.xxx.com",
                    [
                        Headers = [
                            #"Content-Type" = "application/json",
                            Authorization = "Bearer " + token,
                            RelativePath = "/xxxxx/xxxxx"
                        ]
                    ]
                )
        in
            Result

        Regards,

        Xiaoxin Sheng

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks Anonymous for your inputs. Will explore on this.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Go to Data source settings, Select the connection from the list to which you are connecting. Click on edit permissions and check it's set to anonymous, if not then set it to anonymous.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous that is a great suggestion, I was able to move to the next stage, but encountering a different issue. Is this something to do with the parameters I am passing? Any suggestion on this?

     

    This is the screenshot of parameters I'm passing.

     

     

    This is the error I am getting

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous Try to do it from advance editor query and Put the code as below. Power BI is taking your request as a GET request instead of POST request so you need to create it as a post request.

       

      You are passing these values in Headers but these should be passed in the body part. 

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Thank you Anonymous, I will check this and get back.