Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

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

lojithlk_0-1645782352159.png

Getting the below error.

 

lojithlk_1-1645782428242.png

 

 

Getting the response from Postman.

Please advise.

 

Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

View solution in original post

13 REPLIES 13
vannda21
Helper I
Helper I

Hello @Anonymous ,
Does it work for you now?

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.

 

lojithlk_0-1646232956372.png

lojithlk_1-1646233016971.png

 

This is the error I am getting

 

lojithlk_2-1646233053359.png

 

 

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. 

 

shashinonu_0-1646289963516.png

 

Anonymous
Not applicable

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

Anonymous
Not applicable

@Anonymous did it work for you?

Anonymous
Not applicable

@Anonymous I had encountered some other issue. So i created it as a function and called the function.

 

lojithlk_0-1646656748056.png

 

Anonymous
Not applicable

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

Anonymous
Not applicable

@Anonymous totally agree, that was a wonderful pointer.. accepting this as a solution. One should not pass credential in the header but should be passed along in the body.

Thank you!

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
Not applicable

Thanks @Anonymous for your inputs. Will explore on this.

ghumarepratik21
Regular Visitor

Hello,

You will require authentication key for that API to use header. If you have details you can enter and issue will get resolved.
For refrence you can check below link,
https://www.google.com/search?q=connect+api+with+power+bi&rlz=1C1YQLS_enIN975IN975&oq=connect+api+wi...

Thanks,
Prateek G

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
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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.