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:
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/
Yeah as you noted, you are using the wrong token type.
WebSockets only accepts a user token.
Sounds like you generated an implict auth token with a different clientID to the one you tried to use in code