How do I read data from EventSub callbacks?

When EventSub hits my callback webhook, the POST, GET, and Headers don’t have the challenge info in them. Where is it stored?

I used PHP to getallheaders(), print_r($_POST) and print_r($_GET) when EventSub sends me a challenge but this is all the data that’s in the request from Twitch.

Headers: Array
(
[Host] => [redacted]
[Connection] => Keep-Alive
[Accept-Encoding] => gzip
[CF-IPCountry] => US
[X-Forwarded-For] => 54.184.54.118
[CF-RAY] => [redacted]
[Content-Length] => 387
[X-Forwarded-Proto] => https
[CF-Visitor] => {“scheme”:“https”}
[User-Agent] => Go-http-client/1.1
[Content-Type] => application/json
[Twitch-Eventsub-Message-Id] => ef689031-7181-4ce2-af19-0743cd05ee13
[Twitch-Eventsub-Message-Retry] => 0
[Twitch-Eventsub-Message-Signature] => sha256=ce4aadf48861a3e29fd65f39873136d65b159f1533e7d5d3cca13bd97289b104
[Twitch-Eventsub-Message-Timestamp] => 2020-12-19T06:20:40Z
[Twitch-Eventsub-Message-Type] => webhook_callback_verification
[Twitch-Eventsub-Subscription-Type] => channel.follow
[Twitch-Eventsub-Subscription-Version] => 1
[CF-Request-ID] => 071b41661400003a029e9d0000000001
[CF-Connecting-IP] => 54.184.54.118
[CDN-Loop] => cloudflare
[X-HTTPS] => 1
)
$_POST Array
(
)
$_GET Array
(
)

Okay I figured it out, I didn’t realize you need to do some silly stuff to get PHP to read headers from content-type json.

The solution was to use this code:
$json = file_get_contents(‘php://input’);
$myPostData .= print_r(json_decode($json, TRUE),true);
This creates an ugly string called $myPostData with the info in it. Hopefully this info helps someone else some day.

Yeah that is the correct way to read “incoming body data” in PHP

As Webhooks/Eventsub/PayPay IPN/other kinds of webhooks, they send a POST request but they don’t send POST data, so you have to read php://input

Related post on the subject

If you were building an API you’d have the same “fun” with PUT requests via cURL

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