It looks like you’re missing a ‘:’ at the end of the API key before encoding it. With HTTP basic authentication the ‘:’ is necessary, even when the password is blank. So something like var tok = user + ":"; should work.
After further digging it seems its sending the auth details now and after further inspection I am getting this back {type: “ch:service”, error: “company-profile-not-found”}
However using the online api to test using the same number it finds it?
I am having CORS issue while making above Jquery Ajax call
“Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.companieshouse.gov.uk/search/companies. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).”
In your API key registration, did you configured the domain (s) that you are making the Ajax request from? If you do not do this, our API will not negotiate permission with the CORS protection implemented by your client.
Generally, an API with CORS protection will compare the Origin: header sent by a JS client against an authorisation list. If a match is made, an Access-Control-Allow-Origin: matched-domain is sent back which authorises the client.
Log onto the developer hub and edit your API key to review and/or correct the details. If everything is as it should be, come back with more info and we’ll take a look.
I am getting this error No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://rcidirect.co.uk:8109’ is therefore not allowed access. The response had HTTP status code 401
But that domain is in my application specification !
I have been trying to get it working from last 2 days but it doesn’t work. I am using the same example and I am sending the request from the JavaScript Domain which I registered at Companies house.
It would be great if someone send a full complete example. It shouldn’t be that hard connecting to REST API in 2016. I have even used Fiddler to send a request but I keep getting 401 Unauthorized error.