# Request with fetch() is not authorized

**URL:** <http://forum.companieshouse.gov.uk/t/request-with-fetch-is-not-authorized/1449>\
**Category:** API Issues\
**Created:** [November 8, 2017, 4:35pm UTC](http://forum.companieshouse.gov.uk/t/request-with-fetch-is-not-authorized/1449 "2017-11-08T16:35:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![catalina\_tudor](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@catalina\_tudor](http://forum.companieshouse.gov.uk/u/catalina_tudor)\
**Post date:** [November 8, 2017, 4:35pm UTC](http://forum.companieshouse.gov.uk/t/request-with-fetch-is-not-authorized/1449/1 "2017-11-08T16:35:28Z")

</div>

Hi,

Sorry if this is related to other questions that have been answered. I’m new to this and I’m trying to do a simple fetch to pull data from the API and then console.log the results. This is my code:

```
  var key = 'API_KEY:';
  var headers = new Headers({
      'Authorization': 'Basic ' + btoa(key),
      'Content-Type': 'text/json',
  });
    
  var obj = {
    mode: 'no-cors',
    method: 'GET',
    headers: headers
  }

  fetch('https://api.companieshouse.gov.uk/search/companies', obj).then(function(res) {
    return res.json();
  }).then(function(res) {
    console.log(res);
  }).catch(function(err) {
    console.log(err);
  });

```

I’ve mapped localhost to a domain like: [domain.com](http://domain.com) and then assign [http://domain.com](http://domain.com) to the Javascript domains field on the Companies House website but I still get 401 (Unauthorized) error. Was wondering if someone can help me understand what I’m doing wrong. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![catalina\_tudor](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@catalina\_tudor](http://forum.companieshouse.gov.uk/u/catalina_tudor)\
**Post date:** [November 8, 2017, 10:55pm UTC](http://forum.companieshouse.gov.uk/t/request-with-fetch-is-not-authorized/1449/2 "2017-11-08T22:55:38Z")

</div>

Resolved. After researching on the internet, I’ve found out that, using fetch() with `no-cors` mode is not sending the authorised header and that’s why I was receiving the response.
