Cannot Connect KNIME to Companies House via REST API (get 401 Error)

Hi Everyone

First off - I've gone in the first instance here on the Companies House developer forum. No responses as yet.

http://forum.aws.chdev.org/t/401-error-accessing-api-through-knime/1211

As it seems more of a KNIME issue than an API issue I thought I'd try here.

To access the API, you need an 'App' and a token. I have signed up for both of those. I've then tried to perform some simple 'GET' requests using KNIME, e.g. a search for all companies with 'Tesco' somewhere.

"https://api.companieshouse.gov.uk/search/companies?q=Tesco"

The documentation says that it uses BASIC authentication; but your token is your username and there is no password. I've therefore put my generated token in the 'User' field in the KNIME node.

https://developer.companieshouse.gov.uk/api/docs/index/gettingStarted/ap...

But this returns a '401' error; the console outputs:

ERROR GET Request          4:1        Execute failed: Wrong status: 401 Unauthorized

I'm able to use my token to access data through the API on the built-in test, and through a REST client in firefox - and I've double(triple)-checked my typing of the API token...

So I'm not sure what to do. Some developer threads on the forum suggest that the key may need to be base-64 encoded before sending - e.g. http://forum.aws.chdev.org/t/powershell-method/843; http://forum.aws.chdev.org/t/getting-invalid-authorization/41/6

As per the second link, I've tried using the online base64 encoder, copying and pasting it in, but no joy... still 401.

Any thoughts/help gratefully received!

Neil

Hi Neil,

I've found a solution for you using the GET request function.

Indeed you do need to convert your API Key to be Base64 Encoded.

You can do this by using the following website https://www.base64encode.org/

Just remember to add a colon (:) at the end of your API key, when you convert to Base64 encoding.

Then it's a simple header parameter using the Request headers tab with the Authorization details.

Header Key - Authorization, Header Value - Basic <insert Base64 Encoded API Key Here>, Value kind (Constant)

I've attached an example for your to use in your workflow. Let me know if it works for you.

All the best,
Geoff

 

Hi Geoff

You sir, are brilliant. I thought I'd tried all that, but was getting stuck on using the Authentication tab in the node, rather than in the header.

I've just run it and it worked very nicely. That'll keep me going for a while!

Thank you very much

Neil

No problem Neil, glad I could help get it working for you!