Welcome. The lines you show:
GET https://api.companieshouse.gov.uk/company net::ERR_ABORTED 401
(That’s a 401 unauthorized error) … which suggests that either there was something wrong with your API key (or the whole of the Authorization header) OR you were calling the API from a IP address you haven’t registered with them. (You might get a 403 response in that case though.)
If you’ve registered an IP address when you signed up but were using localhost as a development server you should check the following workaround:
https://forum.aws.chdev.org/t/grant-access-for-local-developers-machine/2025
SyntaxError: Unexpected end of input
…is obviously because your code is trying to parse a stream as json but there is no (JSON) body in this case - you might want to trap that.
After you’ve resolved that part, probably the next place to start would be the documentation of the API:
https://developer.companieshouse.gov.uk/api/docs/
You’re calling the company profile endpoint. The documentation for company profile shows you that you need to send in a company number. (The documentation could possibly be improved with a worked example - but it has a live “try it out” feature…).
So try the following at the start of your code:
var compprofile = 'https://api.companieshouse.gov.uk/company/';
// Company "numbers" are strings, currently always 8 characters. Leading zeros are significant.
var company = '00048839'; // barclays bank
var url = compprofile + company;
// Your API key goes below
// (as per the example thread post you mentioned you need a colon after that
// e.g. 'MyAPIKey2843298:')
var key = '.........';
...
You should get something like the json below:
{
"jurisdiction": "england-wales",
"undeliverable_registered_office_address": false,
"last_full_members_list_date": "2012-08-31",
"accounts": {
"next_made_up_to": "2020-12-31",
"overdue": false,
"next_due": "2021-06-30",
"last_accounts": {
"made_up_to": "2019-12-31",
"period_end_on": "2019-12-31",
"type": "group",
"period_start_on": "2019-01-01"
},
"accounting_reference_date": {
"month": "12",
"day": "31"
},
"next_accounts": {
"period_start_on": "2020-01-01",
"overdue": false,
"period_end_on": "2020-12-31",
"due_on": "2021-06-30"
}
},
"registered_office_address": {
"postal_code": "E14 5HP",
"locality": "London",
"address_line_1": "1 Churchill Place"
},
"company_number": "00048839",
"company_name": "BARCLAYS PLC",
"type": "plc",
"has_been_liquidated": false,
"date_of_creation": "1896-07-20",
"sic_codes": [
"64110",
"70100"
],
"etag": "48a27160106b9459983d0a1473726bd7e3028b53",
"company_status": "active",
"has_insolvency_history": false,
"previous_company_names": [
{
"effective_from": "1896-07-20",
"name": "BARCLAYS BANK PLC",
"ceased_on": "1985-01-01"
}
],
"has_charges": false,
"confirmation_statement": {
"next_due": "2021-04-15",
"next_made_up_to": "2021-04-01",
"last_made_up_to": "2020-04-01",
"overdue": false
},
"links": {
"self": "/company/00048839",
"filing_history": "/company/00048839/filing-history",
"officers": "/company/00048839/officers",
"exemptions": "/company/00048839/exemptions"
},
"registered_office_is_in_dispute": false,
"can_file": true
}
Good luck.