# \[EventSub WS\] 400 Bad Request - The value specified in the method field is not valid

**URL:** <https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198>\
**Category:** API\
**Created:** [June 21, 2023, 1:20pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198 "2023-06-21T13:20:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_AI\_fu\_DEV](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@w\_AI\_fu\_DEV](https://discuss.dev.twitch.com/u/w_AI_fu_DEV)\
**Post date:** [June 21, 2023, 1:20pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/1 "2023-06-21T13:20:33Z")

</div>

Hi, I am getting this error when trying to subscribe to any events.  
Here is the code I am using for the subscription:

```auto
function subscribeToEventSub(event_name: string, version: number, condition: any = {}, app_token: string, session_id: string): void {
    fetch('https://api.twitch.tv/helix/eventsub/subscriptions', {
        method: 'POST',
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + app_token,
            "Client-Id": "<APP CLIENT ID>",
            "type": event_name,
            "version": version.toString(),
            "condition": JSON.stringify(condition), // {"broadcaster_user_id": user_id}
            "transport": JSON.stringify({
                "method": "websocket",
                "session_id": session_id
            })
        }
    })
    ...
}

```

`app_token` is obtained using this piece of code:

```auto
async function getTwitchAppAccessToken(): Promise<string> {
    let req = await fetch(`https://id.twitch.tv/oauth2/token`
                          + `?client_id=<APP CLIENT ID>`
                          + `&client_secret=<APP CLIENT SECRET>`
                          + `&grant_type=client_credentials`,
    {
        method: 'POST'
    });
    let resp = await req.json();
    return resp["access_token"]; // pardon the lack of error checking
}

```

It is very likely that my error is linked to this:

> [If you use WebSockets to receive events, the request must specify a user access token](https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription)

So I also tried replacing the `Authorization` token with one gotten from the implicit grant flow.  
Here is the url I am using (I successfully manage to get the asked tokens, no problems here):

```auto
`https://id.twitch.tv/oauth2/authorize`
+ `?client_id=<APP CLIENT ID>`
+ `&redirect_uri=http://localhost:3000/callback`
+ `&response_type=token+id_token`
+ `&scope=channel:read:subscriptions+moderator:read:followers+bits:read+openid`

```

But with the `Authorization` token set to use the one from the implicit grant flow, I get another error:

> The ID in the Client-Id header must match the client ID in the access token.

What am I doing wrong ? 😭

---

<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 21, 2023, 1:26pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/2 "2023-06-21T13:26:12Z")

</div>

Most of your Subscription request is in a header isntead of the body  
And you have a slew of extra JSON stringify’s

Should be more like:

```auto
function subscribeToEventSub(event_name: string, version: string, condition: any = {}, app_token: string, session_id: string): void {
    fetch('https://api.twitch.tv/helix/eventsub/subscriptions', {
        method: 'POST',
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + app_token,
            "Client-Id": "<APP CLIENT ID>"
       },
       body: JSON.stringify({
            "type": event_name,
            "version": version,
            "condition": condition, // {"broadcaster_user_id": user_id}
            "transport": {
                "method": "websocket",
                "session_id": session_id
            }
        }
    })

```

Also note that `version` in the function call should be typecast to a string so you can handle version `beta` and Twitch hasn’t said they’ll always be numeric in style.

You can refer to my code example here which might help you out:

[https://barrycarlyon.github.io/twitch\_misc/eventsub/websockets/web/basic/](https://barrycarlyon.github.io/twitch_misc/eventsub/websockets/web/basic/)

> [@w\_AI\_fu\_DEV](#):
>
> `app_token` is obtained using this piece of code:

Yeah as you noted, you are using the wrong token type.

WebSockets _only_ accepts a user token.

> [@w\_AI\_fu\_DEV](#):
>
> But with the `Authorization` token set to use the one from the implicit grant flow, I get another error:
> 
> > The ID in the Client-Id header must match the client ID in the access token.
> 
> What am I doing wrong ?

Sounds like you generated an implict auth token with a different clientID to the one you tried to use in code

---

<div class="post-metadata">

**Author:** ![w\_AI\_fu\_DEV](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@w\_AI\_fu\_DEV](https://discuss.dev.twitch.com/u/w_AI_fu_DEV)\
**Post date:** [June 21, 2023, 1:28pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/3 "2023-06-21T13:28:25Z")

</div>

Thank you for the quick answer, will try it out!

---

<div class="post-metadata">

**Author:** ![w\_AI\_fu\_DEV](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@w\_AI\_fu\_DEV](https://discuss.dev.twitch.com/u/w_AI_fu_DEV)\
**Post date:** [June 21, 2023, 1:45pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/4 "2023-06-21T13:45:03Z")

</div>

Alright, good news is I am no longuer seeing the “The ID in the Client-Id header must match the client ID in the access token.” error.

The bad news is that even after implementing your changes and using a user token, I still get the “The value specified in the method field is not valid” error.

Just to be sure, when refering to “user token”, we are refering to the “access\_token” fragment parameter sent to the callback url, 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:** [June 21, 2023, 1:46pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/5 "2023-06-21T13:46:37Z")

</div>

> [@w\_AI\_fu\_DEV](#):
>
> Just to be sure, when refering to “user token”, we are refering to the “access\_token” fragment parameter sent to the callback url, correct?

For implict auth yes, the access token is in the `access_token` fragment

> [@w\_AI\_fu\_DEV](#):
>
> The bad news is that even after implementing your changes and using a user token, I still get the “The value specified in the method field is not valid” error.

What is you code currently looking like?

---

<div class="post-metadata">

**Author:** ![w\_AI\_fu\_DEV](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@w\_AI\_fu\_DEV](https://discuss.dev.twitch.com/u/w_AI_fu_DEV)\
**Post date:** [June 21, 2023, 1:59pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/6 "2023-06-21T13:59:53Z")

</div>

My bad, I forgot to remove the damned JSON.stringify.  
Everything is working and I am getting an actual response, thank you very much!

---

<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 21, 2023, 2:00pm UTC](https://discuss.dev.twitch.com/t/eventsub-ws-400-bad-request-the-value-specified-in-the-method-field-is-not-valid/46198/7 "2023-07-21T14:00:51Z")

</div>

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