# Missing Header

**URL:** <https://forums.fusetools.com/t/missing-header/5021>\
**Category:** How-to Discussions\
**Created:** [October 5, 2017, 11:53am UTC](https://forums.fusetools.com/t/missing-header/5021 "2017-10-05T11:53:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 11:53am UTC](https://forums.fusetools.com/t/missing-header/5021/1 "2017-10-05T11:53:46Z")

</div>

Hi, please i’m having issues adding an authorization header while calling a REST API using fetch.

I got `Missing authorization header`

Below is my code for making requests to the API

```auto
function AppCloud(api, args, m, body, access_token) {
	var url = API_URL+api+"?rand="+Date.now();
	var requestData = {
		method : m
	};

	if (body !== null){
		requestData.headers = new Headers({
		    'Accept': 'application/json',
		    'Content-Type': 'application/x-www-form-urlencoded',
		    'Authorization': 'Bearer ' + access_token
		  });
		requestData.body = body; 
	}

	//console.log(JSON.stringify(requestData));

	return fetch(url,requestData).then(function(res) {
		return res.json();
	}).catch(function(msg) {
		console.log("Failed to fetch: " + url + ", msg: " + msg);
	}); 
}

```

I have tried the API endpoint in Postman and it worked. Please what are mine doing wrong?

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [October 5, 2017, 12:03pm UTC](https://forums.fusetools.com/t/missing-header/5021/2 "2017-10-05T12:03:24Z")

</div>

Apparently your backend expects a different header or a differently named authorization property or different syntax for the auth header value.

The code looks fine, except maybe the `requestData.body` should be `JSON.stringify(body)`.

---

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 12:07pm UTC](https://forums.fusetools.com/t/missing-header/5021/3 "2017-10-05T12:07:27Z")

</div>

> **Uldis wrote:**  
> The code looks fine, except maybe the `requestData.body` should be `JSON.stringify(body)`.

For the requestData.body, I’m using an encoded data using the function below:

```auto
function formEncode(obj) {
    var str = [];
    for(var p in obj)
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
    return str.join("&");
}

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [October 5, 2017, 12:09pm UTC](https://forums.fusetools.com/t/missing-header/5021/4 "2017-10-05T12:09:40Z")

</div>

I don’t think that’s related to the issue at hand in any way. It’s about what your backend expects you to send from the client, and there is no way for us to help you with that; especially, not knowing what your backend is.

---

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 12:13pm UTC](https://forums.fusetools.com/t/missing-header/5021/5 "2017-10-05T12:13:41Z")

</div>

My backend is PHP (Codeigniter RestServer - [https://github.com/aiamk/codeigniter-restserver](https://github.com/aiamk/codeigniter-restserver))

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [October 5, 2017, 12:29pm UTC](https://forums.fusetools.com/t/missing-header/5021/6 "2017-10-05T12:29:10Z")

</div>

You’ll need to read the docs on that repository, configure you backend as necessary, and make sure you send the exact headers it expects. Good luck!

---

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 12:31pm UTC](https://forums.fusetools.com/t/missing-header/5021/7 "2017-10-05T12:31:52Z")

</div>

> **Uldis wrote:**
> 
> You’ll need to read the docs on that repository, configure you backend as necessary, and make sure you send the exact headers it expects. Good luck!

I’ve done that already and I believe since it’s working through POSTMAN without any hitches, then it should work with fetch too.

Thanks.

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [October 5, 2017, 12:36pm UTC](https://forums.fusetools.com/t/missing-header/5021/8 "2017-10-05T12:36:02Z")

</div>

If it works with Postman and doesn’t work with `fetch`, then all you need to do is figure out what the difference between the two is. There’s nothing else we can do to help.

If you can’t figure it out, please provide a _complete, minimal, ready-to-run_ reproduction that we can copy-paste and run to see the problem.

---

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 12:46pm UTC](https://forums.fusetools.com/t/missing-header/5021/9 "2017-10-05T12:46:50Z")

</div>

It seems I found out what could be the cause.  
I log request headers for postman and fetch and below is the output.

FETCH

```auto
{"status":false,"header":{"Accept":"application/json","Content-Type":"application/x-www-form-urlencoded","authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBhcGFrYXkxOUBnbWFpbC5jb20iLCJ1c2VyX2lkIjoiMTg3IiwiaWF0IjoxNTA3MjA1MDU3LCJleHAiOjE1MDc4MDk4NTd9.yxENA7-8D-TdnkTCrZ2Vyd6mkZVXnAv3ok4-K_6s280","Content-Length":"49","Expect":"100-continue","Host":"apps.dev"}}

```

and POSTMAN

```auto
{"status":true,"header":{"cache-control":"no-cache","Postman-Token":"0649d8c1-bb6d-4e83-99b4-8ba0665cfac0","Content-Type":"application\/x-www-form-urlencoded","Authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InBhcGFrYXkxOUBnbWFpbC5jb20iLCJ1c2VyX2lkIjoiMTg3IiwiaWF0IjoxNTA3MjAxNDc2LCJleHAiOjE1MDc4MDYyNzZ9.uxdyCQs3OrRbCG5ukAFn9Ni5G8mSJrBD9EObEoSYYXk","User-Agent":"PostmanRuntime\/6.3.2","Accept":"*\/*","Host":"apps.dev","accept-encoding":"gzip, deflate","Connection":"keep-alive"}}

```

From Observation Postman passes Authorization key in capitalized format while Fetch does so in lowercase case.

Is there a way to enforce the Case?

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [October 5, 2017, 1:29pm UTC](https://forums.fusetools.com/t/missing-header/5021/10 "2017-10-05T13:29:11Z")

</div>

Now we’re getting somewhere!

I checked our `fetch` implementation and [found this](https://github.com/fusetools/fuselibs-public/blob/34723eec081e50e472edea0471f61919a2889496/Source/Polyfills.Window/js/fetch.js#L56). This approach matches whatever the specification for `fetch` WAS a while ago, but that has changed since. Apparently we need to update our `fetch` implementation (logged [a ticket](https://github.com/fusetools/fuselibs-public/issues/533) about that).

As I see it, you now have two short-term options:

1. Change your backend to accept lowercase header property names.
2. Switch to using `XMLHttpRequest` which doesn’t seem to suffer from this issue.

---

<div class="post-metadata">

**Author:** ![papakay19](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/papakay19/32/510_2.png) [@papakay19](https://forums.fusetools.com/u/papakay19)\
**Post date:** [October 5, 2017, 1:34pm UTC](https://forums.fusetools.com/t/missing-header/5021/11 "2017-10-05T13:34:10Z")

</div>

Thanks. I already went for option 1.

Thank you.
