Webhooks, can't find the data from the notification

Sorry if this turns out to be the most simple of simple questions, I’m struggling and need help!

I’ve setup what I believe to be a working webhook with the Twitch API. To test, I am subscribing to a follow from an id (which is my own Twitch account).

My question is, where in the POST is the data? I’m expecting to find something similar to:

{
   "data":
      [{
         "from_id":"1336",
         "to_id":"1337",
         "followed_at": "2017-08-22T22:55:24Z"
      }]
}

but I can’t work out where that exists in the request I get back (which is large).

Here is my code:

app.get('/api/twitch/callback/', (request, response) => {
  const challenge = request.query['hub.challenge']
  console.log(request.query['hub.topic'])
  console.log(request.params)
  console.log(request.query)
  console.log(challenge)
  response.set({
    'Access-Control-Allow-Origin': '*',
    'x-timestamp': Date.now(),
    'x-sent': true,
  })
  response.status(200).send(challenge)
})

app.post('/api/twitch/callback/', (request, response) => {
  console.log(request)
})

You need the body-parser middleware

Example usage:

const request = require('request');

const bodyParser = require('body-parser');

app.use(bodyParser.json());

app.post('/api/twitch/callback/', (request, response) => {
  console.log(request.body)
})

or

const request = require('request');

const bodyParser = require('body-parser');

app.post('/api/twitch/callback/', bodyParser.json(), (request, response) => {
  console.log(request.body)
})
1 Like

Thanks dude!

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