Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A web API key can only be specified when a web API key name is provided

I was trying to get data from a vendor's REST API from Power BI.

When getting data, under Web API, it keeps throwing this error. See attached screenshot.

Error message screenshot

It is a POST method where you can filter by any field in the response body (yet I'm not passing any this time).

The query I am using to get a response is as below. Sorry I forgot where I found it.

let

    apiUrl = "my_api_url",

    token="my_api_key",

    options = [Headers=[Authorization="Bearer " & token ]],

    result = Json.Document(Web.Contents(apiUrl , options))

in

    #"result"
like image 504
Hanyu Wang Avatar asked Aug 12 '19 19:08

Hanyu Wang


2 Answers

You need to include ApiKeyName in your request rather than building up Authorization yourself.

For example:

let Source = Web.Contents(apiURL, [ApiKeyName="mauapikey"]),

Also see Microsoft Documentation or someone's blog post

like image 76
maulemon Avatar answered Sep 29 '22 06:09

maulemon


I recently ran into a similar problem, but was able to find the solution:

If your authorization must be in the header, you were nearly there with your solution. In my case, the authorization was required to be in the header, but utilized Basic Authentication rather than Token. I believe if you do the following to your code, it will work

let

    apiUrl = "my_api_url",

    token="my_api_key",

    options = [Headers=[#"Authorization"="Bearer " & token ]],

    result = Json.Document(Web.Contents(apiUrl , options))

in

    #"result"

The only thing added is the '#' before the Authorization and then surrounding Authorization with double quotes "Authorization".

like image 44
amrtdc1 Avatar answered Sep 29 '22 07:09

amrtdc1