Hi,
Here’s my code, if I change /advanced-search/ to /search/ then I can connect to the API fine, but as soon as I change it back to /advanced-search/ I get a 404 error.
Access to fetch at ‘https://api.company-information.service.gov.uk/advanced-search/companies?company_name_includes=company’ from origin ‘MY-DOMAIN’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
<script type="text/javascript">
var url = 'https://api.company-information.service.gov.uk/advanced-search/companies?company_name_includes=company';
var headers = new Headers({
Authorization: "Basic " + btoa("APIKEY"),
"Content-Type": "text/json",
});
var obj = {
mode: "cors",
method: "GET",
cache: "no-cache",
headers: headers,
};
fetch(url, obj)
.then((resp) => resp.json())
.then((data) => console.log(data))
.catch(function(err) {
console.log(err);
});
Also, the domains I’m using have been added to the javascript domains for the application.
Any help getting to the bottom of this would be greatly appreciated!
Thanks
Dan