Forum Discussion

DanT1994's avatar
DanT1994
Helper I
2 years ago
Solved

Connect to Web API with custom header

Hi,

 

I'm getting the following error when trying to connect a web API.

Using an online API testing tool, my URL and custom header looks like this:

 

So, I'm maybe simplifying this too much, but in PowerBI i'm entering it like this:



And it's throwing up the following error:



How can I get around this?

Thanks in advance
Dan



  • Anonymous's avatar
    Anonymous
    2 years ago

    HI DanT1994,

    Perhaps you can try opt use following code to use web connector getting data with apikey in anonymous mode:

    let
        url="xxx.xxxxxx.com",
        apiKey = "key",
        headers = [
    
            #"CLICDATA-API-KEY" = apiKey,
            #"Content-Type" = "application/json"
        ],
        path="/api/xxx/xxx",
        request = Web.Contents(url, [ Headers = headers, RelativePath= path])
    in
        request

    Using The RelativePath And Query Options With Web contents 

    Regards,

    Xiaoxin Sheng

8 Replies

  • As it says in the error message - you need to include the authentication either in the header or in the body.

    • DanT1994's avatar
      DanT1994
      Helper I

      Thanks for the reply, please could you expand/advise how I'd do that?  I thought I had included my authentication key in the header (screenshot in original post).

      Thanks

      • lbendlin's avatar
        lbendlin
        Super User

        Go to Data Source settings, clear permissions for the API URL, and on next try use anonymous auth.

    • DanT1994's avatar
      DanT1994
      Helper I

      Unfortunately if I do that, the data source wont be there so the 'edit permissions'/'clear permissions' boxes are greyed out.  There's no way of clearing the permissions at the same time as adding the data source...

      • lbendlin's avatar
        lbendlin
        Super User

        Now would be as good as any time to start over, with a new PBIX file...

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI DanT1994,

    Perhaps you can try opt use following code to use web connector getting data with apikey in anonymous mode:

    let
        url="xxx.xxxxxx.com",
        apiKey = "key",
        headers = [
    
            #"CLICDATA-API-KEY" = apiKey,
            #"Content-Type" = "application/json"
        ],
        path="/api/xxx/xxx",
        request = Web.Contents(url, [ Headers = headers, RelativePath= path])
    in
        request

    Using The RelativePath And Query Options With Web contents 

    Regards,

    Xiaoxin Sheng