# Authentication failure when refreshing through Power BI Service

**URL:** <http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177>\
**Category:** API Issues\
**Created:** [March 5, 2025, 10:06am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177 "2025-03-05T10:06:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![support.buses.datama](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/a698b9/32.png) [@support.buses.datama](http://forum.companieshouse.gov.uk/u/support.buses.datama)\
**Post date:** [March 5, 2025, 10:06am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/1 "2025-03-05T10:06:45Z")

</div>

I have made a report requesting company information from Companies House. I have a key, and the query works well in Power BI Desktop/Power Query, where “Data source settings” accepts the API key as user name and no password.  
When I try to set it up for automatic refresh in Power Query Service (no gateway), it fails, as I can’t use blank password, the UI requires a password to store the information.  
Has anybody managed to trick Power Query Service and in the next step Companies House API with a suitable password? I have tried space, Power Query Service saves the information but I get a 400 response.

This sounds fairly similar to [Http Basic Authentication requires NO password](https://forum.aws.chdev.org/t/http-basic-authentication-requires-no-password/1881)

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [March 5, 2025, 1:49pm UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/2 "2025-03-05T13:49:25Z")

</div>

I don’t use Power BI but a quick Google suggests that you should be able to work around any user interface issues by building and supplying your own http header fields using Power Query M Language. Here’s the article I found (I have nothing to do with the author and have not tried this …):

> **[Encoding basic authentication in an url with Power Query/M language](https://seddryck.wordpress.com/2017/06/22/encoding-basic-authentication-in-an-url/)**
>
> More than one year ago, I edited a blog post about how to get data from Neo4j with Power BI and yesterday, Chris Skardon published a cover enriched with more details (useful if you’re new to …

For reference (in case link goes dead) this amounts to something like (again I have no idea if this syntax is correct or the following works):

```auto
let
  User = "Your API key here",
  Password = "",
  Plaintext = User & ":" & Password,
  Bytes = Text.ToBinary(Plaintext),
  Credentials = Binary.ToText(Bytes, BinaryEncoding.Base64)
  Source = Web.Contents( "https://api.company-information.service.gov.uk/company/02604354",
    [
      Headers = [#"Authorization" = "Basic " & Credentials],
    ]
  )
in
  Source

```

Normally it is best to let the tool / interface / library do that for you if the option is available, but if an interface really refuses to allow you to have a specific value (e.g. blank) then this would be the way to work around the issue.

If you search this forum (magnifying glass icon in the top right on the Desktop version of the site) you will find quite a few threads dealing with Power BI etc. which may also help

Normally for “authentication failed” I would expect that you would get a 401 rather than a 400. However it may be that entering a space causes the http Basic header to be incorrectly formed by Power BI. Or perhaps Companies House just returns a 400 if there is anything in the password?

Good luck.

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [March 5, 2025, 6:31pm UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/3 "2025-03-05T18:31:40Z")

</div>

Can’t seem to edit that last but probably needs a comma at the end of the credentials line, before the “Source = …” line.

---

<div class="post-metadata">

**Author:** ![support.buses.datama](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/a698b9/32.png) [@support.buses.datama](http://forum.companieshouse.gov.uk/u/support.buses.datama)\
**Post date:** [March 6, 2025, 7:18am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/4 "2025-03-06T07:18:38Z")

</div>

The Power Query/M part is working, in Power BI Desktop, pretty much as you suggest. It is when I publish the report, and want it to be refreshed on schedule in Power BI Service (“cloud”) that it is not enough with the code inside the semantic model, I also need to do an authentication in the service environment, and this authentication requires a password. As Companies House take the key as userID, and expects exactly nothing as password, this fails.  
But thanks for your interest and suggestion!

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [March 6, 2025, 8:32am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/5 "2025-03-06T08:32:43Z")

</div>

Ah - in which case have you seen this article on creating a custom connector? (Again - I’ve no idea if this will do what you need, it just seems that others have managed to find a way):

> **[Chris Webb's BI Blog: Using OpenApi.Document() To Create A Power BI Custom...](https://blog.crossjoin.co.uk/2018/11/13/openapi-power-bi-rest-api-m/)**
>
> The idea of creating a Power BI custom connector for the Power BI REST API is not a new one: Miguel Escobar wrote one earlier this year (see here for the source code and documentation). However the…

Looks like you wouldn’t need all of this as a) this one is for OAuth and b) reads an OpenApi definition file - there isn’t an official one for Companies House I think. But it does look like it’s possible to write code for the online (not desktop) Power BI service, rather than just having to put values in dialog boxes.

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [March 6, 2025, 8:34am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/6 "2025-03-06T08:34:46Z")

</div>

Of course at that point you may have _other_ problems (e.g. Companies House usually requires that you register your key to one of a few IP addresses or (if using AJAX) domain names, which may be more difficult with a cloud-based service (it may not for this one, I don’t know…)

---

<div class="post-metadata">

**Author:** ![support.buses.datama](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/s/a698b9/32.png) [@support.buses.datama](http://forum.companieshouse.gov.uk/u/support.buses.datama)\
**Post date:** [March 6, 2025, 11:53am UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/7 "2025-03-06T11:53:18Z")

</div>

Solved. But I almost don’t know how.  
I **think** I managed by adding the key as User ID in the source authentication dialogue, then a space (or anything) as password, “Skip test connection” unchecked. This results in an error from the source (Companies House’s API), but fear not! Remove the space (or anything) and check “Skip test connection” and “Save”.  
Now I could let Power BI Service refresh, manually triggered, and set a schedule, which was triggered as expected. Tadaa!

---

<div class="post-metadata">

**Author:** ![voracityemail](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/v/b77776/32.png) [@voracityemail](http://forum.companieshouse.gov.uk/u/voracityemail)\
**Post date:** [March 6, 2025, 4:42pm UTC](http://forum.companieshouse.gov.uk/t/authentication-failure-when-refreshing-through-power-bi-service/11177/8 "2025-03-06T16:42:02Z")

</div>

Glad that works for you, thanks for posting a solution for other users.
