# Help me for code

**URL:** <https://discuss.dev.twitch.com/t/help-me-for-code/38842>\
**Category:** API\
**Created:** [June 7, 2022, 3:37am UTC](https://discuss.dev.twitch.com/t/help-me-for-code/38842 "2022-06-07T03:37:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![urexpect](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/urexpect/32/18448_2.png) [@urexpect](https://discuss.dev.twitch.com/u/urexpect)\
**Post date:** [June 7, 2022, 3:37am UTC](https://discuss.dev.twitch.com/t/help-me-for-code/38842/1 "2022-06-07T03:37:44Z")

</div>

```auto
function getUser(username) {
return fetch(`https://api.twitch.tv/helix/users?login=${username}`, {
    method: "GET",
    headers: {
        'Client-ID': "csj7l3h1nqr7iyd1vudl79q21dcen9",
        "Authorization": "OAuth pyfhpx64tz6z4fvpb1xf6lrix6gpi9",
        'Accept': 'application/vnd.twitchtv.v5+json'
    }
}).then(async (res) => res.json())
};

```

Result

```auto
{ error: 'Not Found', status: 404, message: 'This API does not exist' }
{
  error: 'Unauthorized',
  status: 401,
  message: 'The "Authorization" token is invalid.'
}

```

But my token true ☹ help me pls

---

<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:** [June 7, 2022, 11:13am UTC](https://discuss.dev.twitch.com/t/help-me-for-code/38842/2 "2022-06-07T11:13:48Z")

</div>

> [@urexpect](#):
>
> `'Accept': 'application/vnd.twitchtv.v5+json'`

Dont need this header

> [@urexpect](#):
>
> `"Authorization": "OAuth pyfhpx64tz6z4fvpb1xf6lrix6gpi9",`

Don’t leak generated tokens

The prefix for helix is `Bearer` not `oAuth` so your headers should be:

```auto
return fetch(`https://api.twitch.tv/helix/users?login=${username}`, {
    method: "GET",
    headers: {
        'Client-ID': "csj7l3h1nqr7iyd1vudl79q21dcen9",
        "Authorization": "Bearer MyToken",
    }
})

```

Code example demonstrating this kind of call [Twitch Implicit Auth Example](https://barrycarlyon.github.io/twitch_misc/authentication/implicit_auth/)

---

<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:** [July 7, 2022, 11:14am UTC](https://discuss.dev.twitch.com/t/help-me-for-code/38842/3 "2022-07-07T11:14:03Z")

</div>

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