Axios first attempt

Hi,

This is my first attempt, so sorry if this has a very obvious solution.

I’ve crawled through the questions and haven’t been able to find a clear solution. I have been trying to do a simple get request (via Axios), I have done this on APIs that didn’t need authorisation, but cannot seem to work out how to do it for companies house.
My request is basically:

const res = await axios.get(https://api.company-information.service.gov.uk/company/06219884/officers, { ‘headers’: { ‘Authorization’: token } });

Please can you let me know where I’m going wrong. I only want to just do a basic get request for the directors of a company, so if I’ve overcomplicated this please let me know.

What error do you get? Is this running in the browser or in a Node app?

Can you put your code into a github gist? This will allow for easier debugging.

There’s missing quotes from your URL and it’s not clear if you’ve added the token properly to the header.

The API uses http basic auth with the key as the username and no password. To specify basic auth in axios, you use a specific ‘auth’ option, which you are missing. Also, put the URL in single quotes. The request should be something like:

axios.get(’…url…’, { auth: { username: ‘…key…’ , password: ‘’ } } );