# I need example webhooks "Topic: Subscription Events" with nodejs

**URL:** <https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756>\
**Category:** API\
**Created:** [July 9, 2019, 6:23am UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756 "2019-07-09T06:23:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![twitch\_go](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/twitch_go/32/6664_2.png) [@twitch\_go](https://staging-discuss.dev.twitch.com/u/twitch_go)\
**Post date:** [July 9, 2019, 6:23am UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/1 "2019-07-09T06:23:21Z")

</div>

this is my code.

```
var clientID = 'myID'
		var contentType = 'application/json'
		var postURI = 'https://api.twitch.tv/helix/webhooks/hub'
		var secret = 'secretvalue'
		var options =
			{
				headers: {
					'Client-ID': clientID,
					'Content-Type': contentType
				},
				uri: postURI,
				method: 'POST',
				json: {
					"hub.mode":"subscribe",
					"hub.topic":"https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=123456789&first=1",
					"hub.callback":"myCallback",
					"hub.lease_seconds":264000,
					"hub.secret":secret
				}
			}

```

and respone is

```
{ error: 'Bad Request',
 status: 400,
 message: 'auth token is required' } }

```

idk how to use Topic: Subscription Events.

---

<div class="post-metadata">

**Author:** ![Dist](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://staging-discuss.dev.twitch.com/u/Dist)\
**Post date:** [July 9, 2019, 9:06am UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/2 "2019-07-09T09:06:43Z")

</div>

> [@twitch\_go](#):
>
> { error: ‘Bad Request’,  
> status: 400,  
> message: ‘auth token is required’ } }

Just like the error says, you need to use an auth token.

The subscriptions endpoint requires a User Access Token with the `channel:read:subscriptions` scope.

The owner of the channel that you want subscriber data for needs to go through your OAuth process to grant you an auth token, and then you can add it to the request as the `Authorization` header.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [July 9, 2019, 10:45am UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/3 "2019-07-09T10:45:36Z")

</div>

Additionally.

Each Webhook’s topic you can test if you can subscribe to the topic by making a fetch call to the topic as each topic has a corresponding helix end point.

So if you can fetch `https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=123456789&first=1` then you can create a webhook subscription for it. (easy way to test your token is correct without making a subscription and waiting for data to occur or a denied response)

---

<div class="post-metadata">

**Author:** ![twitch\_go](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/twitch_go/32/6664_2.png) [@twitch\_go](https://staging-discuss.dev.twitch.com/u/twitch_go)\
**Post date:** [July 9, 2019, 6:29pm UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/4 "2019-07-09T18:29:53Z")

</div>

thx reply.  
i solved, can respone message ‘Accept’ but no received data from POST.  
my code is \>  
route.post(’/send’,function (req,res) {  
console.log(‘post’);  
req.on(‘data’,function(chunk) {  
var data = ‘’;  
data += chunk.toString();  
var rst = JSON.parse(data);  
console.log(rst);  
});  
res.status(200).send(‘done’);  
});

```
route.get('/send',function (req,res) {
	console.log('get');
	res.status(200).send(req.query['hub.challenge']);
});

```

thank you.

---

<div class="post-metadata">

**Author:** ![twitch\_go](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/twitch_go/32/6664_2.png) [@twitch\_go](https://staging-discuss.dev.twitch.com/u/twitch_go)\
**Post date:** [July 9, 2019, 6:30pm UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/5 "2019-07-09T18:30:30Z")

</div>

thx reply!

i will try this too!

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [August 8, 2019, 6:30pm UTC](https://staging-discuss.dev.twitch.com/t/i-need-example-webhooks-topic-subscription-events-with-nodejs/21756/6 "2019-08-08T18:30:33Z")

</div>

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