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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Can't refresh data because "API Key was expected to be provided in the header for this call"

I've created a dahsboard, of which the source is Lead Forensics' API (they identify businesses veiwing our wensite). 
In desktop I connect without any issues like this:

 

let
Source = Json.Document(Web.Contents("https://interact.leadforensics.com/WebApi_v2/Visit/GetAllVisits?datefrom=01-01-2020 00:00:00&dateto=31-12-2030 23:59:59&pagesize=999999&pageno=1", [Headers=[#"Authorization-Token"="XXXXXXXXXXXXXX", #"ClientID"="XXXXX"]])),
visits1 = Source[SiteVisitList],
#"Converted to Table" = Table.FromList(visits1, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to Table"

 

 

The problem starts when I try to set up a data refresh. In Data Source credentials I get the "Your data source can't be refreshed because the credentials are invalid. Please update your credentials and try again." notification as presented below:power bi 1.jpg


When I get to changing the credentials I wanted to use the standard "Annonymous" and "none" settings like I always do with APIs, but I get this error:
"Failed to update data source credentials: Web.Contents failed to get contents from 'https://interact.leadforensics.com/WebApi_v2/Business/GetAllBusinesses?datefrom=01-01-2010%2000:00:0...' (400): The Lead Forensics API Key was expected to be provided in the header for this call." 
power bi 2.jpg

What am I doing wrong?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I have finally managed to solve the problem witrh a little bit of help from @blopez11 which he posted here

 

let
vBaseUrl = "https://interact.leadforensics.com",
vPath = "WebApi_v2/Visit/GetAllVisits?datefrom=01-01-2020 00:00:00&dateto=31-12-2030 23:59:59&pagesize=999999&pageno=1",
vHeaders = [#"Authorization-Token"="THIS IS WHERE I PUT THE AUTH TOKEN", #"ClientID"="THIS IS WHERE I PUT THE ID"],
Source = Web.Contents ( vBaseUrl, [RelativePath=vPath, Headers=vHeaders] ),
Json = Json.Document ( Source ), SiteVisitList = Json[SiteVisitList],
#"Converted to Table" = Table.FromList(SiteVisitList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
in
#"Converted to Table"

 

 Awesome thanks, you're amazing man!

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

I have finally managed to solve the problem witrh a little bit of help from @blopez11 which he posted here

 

let
vBaseUrl = "https://interact.leadforensics.com",
vPath = "WebApi_v2/Visit/GetAllVisits?datefrom=01-01-2020 00:00:00&dateto=31-12-2030 23:59:59&pagesize=999999&pageno=1",
vHeaders = [#"Authorization-Token"="THIS IS WHERE I PUT THE AUTH TOKEN", #"ClientID"="THIS IS WHERE I PUT THE ID"],
Source = Web.Contents ( vBaseUrl, [RelativePath=vPath, Headers=vHeaders] ),
Json = Json.Document ( Source ), SiteVisitList = Json[SiteVisitList],
#"Converted to Table" = Table.FromList(SiteVisitList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
in
#"Converted to Table"

 

 Awesome thanks, you're amazing man!

lbendlin
Super User
Super User

Your ApiKeyName seems to be "x-api-key".

Anonymous
Not applicable

I took a guess, cause that's the API Key Name I've seen somewhere else. Sadly it didn't work. Neither did "'Authorization-Token" as a name. 

lbendlin
Super User
Super User

Anonymous
Not applicable

Thanks. Do you mean I should add the api key (which is the same as authorization token) like this:

" Source = Json.Document(Web.Contents("https://interact.leadforensics.com/WebApi_v2/Visit/GetAllVisits?datefrom=01-01-2020 00:00:00&dateto=31-12-2030 23:59:59&pagesize=999999&pageno=1", [Headers=[#"Authorization-Token"="XXXXXXXXXXXX", #"ClientID"="XXXXX", #"x-api-key"="XXXXXXXXXXXX"]])),"
?


Or add the "api key's name" (which I don't know) ?

lbendlin
Super User
Super User

Web.Contents has an option specifically for the API Key. use it.

Anonymous
Not applicable

can you elaborate? Am I supposed to make changes in M in desktop ?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.