Webhooks: Properly handle http POST from Twitch

Hey! Really hope this hasn’t been answered before (if so, my apologies, I was unable to find someone with a similar issue), but I’m trying to wrap my head around webhooks and specifically POST requests sent from Twitch to my local server.
Subscribing to any topic works perfectly fine, but once an event happens, the POST request from Twitch initially just seems to contain a number of headers, but no body.

I spent several hours experimenting and trying to pass a 100 status code (either with or without the {‘Expect’:‘100-continue’} header) as a response to the POST, hoping Twitch to again respond with the body containing the infotmation on the event, but apparently my response is not being processed. I can pass a 200 code at any time, which makes Twitch stop trying to reach out to my server (indicating that generally, my responses do reach Twitch), but that doesn’t solve the issue of the missing body.

Whenever I don’t immediately return a 200 code, however, Twitch retries and this time, on consecutive POST requests from Twitch, the event information is contained in the shape of a buffer (which is fine, would prefer JSON, but I can use that).
Now, it feels to me, I’m missing something very simple. I could tell my server to always wait for the first retry, parse the information contained in the buffer and then return a 200 status code to conclude our exchange, but that can’t be the most elegant solution. What am I missing?

I really appreciate the help! Best

What language are you attempting to use?

When Twitch (well Everyone that does Webhooks) sends your Webhook data, it is a request of type POST but the data is in the BODY of the request.

And you should reply with a 200 OK not a 100.

if you are using PHP

$webhook_data = file_get_contents(‘php://input’);

If you are using NodeJS, use bodyParser.json middleware

This sounds odd and more like your handler is doing something unexpected.

Thank you for the quick response! I’ve been using the standard NodeJS http api (sorry, should have specified). After your suggestion to use bodyParser.json, I started looking into the express module and now rewrote the entire request handler using that. Turns out, the handler indeed didn’t process the body correctly the whole time (still kinda new to this^^).
Works perfectly now, thanks a lot! (:


Yeah Express + BodyParser will save you a lot of hassle in general with node

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