# Get request header issue

**URL:** <https://discuss.dev.twitch.com/t/get-request-header-issue/27729>\
**Category:** API\
**Created:** [August 16, 2020, 12:41pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729 "2020-08-16T12:41:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/nicholas/32/9996_2.png) [@Nicholas](https://discuss.dev.twitch.com/u/Nicholas)\
**Post date:** [August 16, 2020, 12:41pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/1 "2020-08-16T12:41:53Z")

</div>

I am currently trying to send a get request to ‘[https://api.twitch.tv/helix/streams](https://api.twitch.tv/helix/streams)’, but I am having some issues. I have used the following header described in [https://dev.twitch.tv/docs/api/reference#get-streams](https://dev.twitch.tv/docs/api/reference#get-streams), but keep getting a response 400 ‘bad request’ sent back.

head = {  
‘client-id’:client\_id,  
‘Authorization Bearer’:token  
}

Looking at it again it looks like instead of ‘Authorization Bearer’:token I should have added 'Bearer ’ to the beginning of the token string and just used ‘Authorization’:. I tried this as well, but to no avail. This time, however, I got a status 401 ‘invalid OAuth token’ reply.

I have registered a developer application at [https://dev.twitch.tv/console](https://dev.twitch.tv/console), where I took the client id from and generated a few clients secrets that I have tried using with it, but none of these have worked. I’m not sure if my formatting is incorrect or if my token is bad. I would greatly appreciate any help that anyone has to offer.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 16, 2020, 12:44pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/2 "2020-08-16T12:44:09Z")

</div>

> [@Nicholas](#):
>
> head = {  
> ‘client-id’:client\_id,  
> ‘Authorization Bearer’:token  
> }

should be

```auto
head = {
'client-id': client_id,
'Authorization': 'Bearer ' + token
}

```

---

<div class="post-metadata">

**Author:** ![Nicholas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/nicholas/32/9996_2.png) [@Nicholas](https://discuss.dev.twitch.com/u/Nicholas)\
**Post date:** [August 16, 2020, 12:52pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/3 "2020-08-16T12:52:14Z")

</div>

thanks for the speedy reply. I tried that as well, but I ran into a slightly different issue of it returning ‘invalid OAuth token’. Is the way in which I got the OAuth token correct?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 16, 2020, 12:53pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/4 "2020-08-16T12:53:53Z")

</div>

Make sure it’s `BearerSPACEtoken` and you can check your tokens validity using [the validate endpoint](https://dev.twitch.tv/docs/authentication#validating-requests)

Any valid token (user or app access) will work for the Streams endpoint

---

<div class="post-metadata">

**Author:** ![Nicholas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/nicholas/32/9996_2.png) [@Nicholas](https://discuss.dev.twitch.com/u/Nicholas)\
**Post date:** [August 16, 2020, 1:05pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/5 "2020-08-16T13:05:12Z")

</div>

I have the space after ‘Bearer’. I just generated a new token using the [https://dev.twitch.tv/console/apps](https://dev.twitch.tv/console/apps) and tried to get request the validate endpoint, but that also returned a status 401 indicating that the access token i just generated is invalid. Is there some reason that the secrets I just generated would be invalid?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 16, 2020, 1:06pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/6 "2020-08-16T13:06:48Z")

</div>

You can’t generate a token via the console.

This sounds like you generated a new client secret and you are trying to use your client secret.

You need to use your cleintID and secret to generate a token.

This covers how to generate an App Access Token

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

---

<div class="post-metadata">

**Author:** ![Nicholas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/nicholas/32/9996_2.png) [@Nicholas](https://discuss.dev.twitch.com/u/Nicholas)\
**Post date:** [August 16, 2020, 1:24pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/7 "2020-08-16T13:24:20Z")

</div>

I have now tried sending a post request to [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token). It told me that I am missing a client secret.

```
head = {
		'client-id':client_id,
		'client_secret':client_secret,
		'grant_type': 'client_credentials'
}

r = requests.post(API_ENDPOINT,headers = head)

```

Also there may be a typo in the docs. It says to use client\_id in the header, but when i used that it said i was missing a client id. I also tried client-secret in the header, but that did not work.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 16, 2020, 1:25pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/8 "2020-08-16T13:25:49Z")

</div>

You don’t send a header to the `OAuth client credentials flow` endpoint

It’s sent as query string or POST body data

Node JS Example:

> <https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/app_access_tokens/nodejs/twitch.js#L47>

---

<div class="post-metadata">

**Author:** ![Nicholas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/nicholas/32/9996_2.png) [@Nicholas](https://discuss.dev.twitch.com/u/Nicholas)\
**Post date:** [August 16, 2020, 1:33pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/9 "2020-08-16T13:33:58Z")

</div>

Thank you for your patience. For anyone that may need this:

> head = {  
> ‘client\_id’:client\_id,  
> ‘client\_secret’:client\_secret,  
> ‘grant\_type’: ‘client\_credentials’  
> }
> 
> r = requests.post(API\_ENDPOINT,data = head)

Note: client\_id is used here, not client-id as i previously thought.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [September 15, 2020, 1:37pm UTC](https://discuss.dev.twitch.com/t/get-request-header-issue/27729/10 "2020-09-15T13:37:49Z")

</div>

Closed on September 15, 2020, 1:37pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
