Greetings! Recently I’ve been working on Twitch API and faced some issues while configuring a webhook for streamings. I have a VPS, which can be accessible from both browser and Postman, but I cannot receive the hub.challenge after sending the subscription request to https://api.twitch.tv/helix/webhooks/hub.
VPS Configuration
The OVH VPS runs a nodejs server inside a docker container, which exposes the ports 8080 and 443. The server handles both GET and POST requests:
app.get('/twitch*', (request, response) => { // Should get the hub.challenge, but no response // Send back the hub.challenge }) https.createServer({ key: privateKey, cert: certificate }, app).listen(PORT);
Before using a nodejs server, I also implemented a Flask Python server.
from flask import Flask, request app = Flask(__name__) @app.route('/twitch/streams', methods=['POST','GET']) def result(): print(request.args.get('uuid')) print(request) return 'Received !' if __name__ == '__main__': app.run(debug=True, use_reloader=True,ssl_context=('cert.pem', 'key.pem'))
I also tried using ssl_context=“adhoc”, but with no results.
Python subscriber
A python script sends the subscription request. I tried using a library, but when I realized that I wasn’t receiving anything, I tried to implement a simple script:
import requests p = requests.post("https://api.twitch.tv/helix/webhooks/hub", headers = {'Client-ID': 'MyClientId', 'Authorization': 'Bearer MyAuthToken'}, params = { "hub.mode":"subscribe", "hub.topic":"https://api.twitch.tv/helix/streams?user_id=UserIWantToWatch", "hub.callback":"http://MyVPSIp:8080/twitch", "hub.lease_seconds":"660" }) print(p, p.content)
Both the simple script and the library return 202, with empty content.
I have noticed that when I start the server without using certificates, It receives some requests from Amazon’s IPs, but with 400 error and unreadable messages. Have you any clues on how to fix this? Thank you!