EventSub provides data in a transport agnostic way.
Currently EventSub only provides a Webhook transport
$CSoutput = json_decode(curl_exec($CScurl),true);
curl_close($CScurl);
should be something like
$CSoutput = curl_exec($CScurl);
$CSinfo = curl_getinfo($CScurl);
curl_close($CScurl);
if ($CSinfo['http_code'] == 200) {
$CSjson = json_decode($CSoutput);
if (json_last_error() == JSON_ERROR_NONE) {
echo 'Got JSON';
print_r($CSjson);
} else {
echo 'Got a JSON decode error with ' . $CSoutput;
}
} else {
echo 'Got a ' . $CSinfo['http_code'] . ' with ' . $CSoutput;
}
The Twitch documentation describes how to do things in the lowest common denominator of cURL.
Then you can take that and convert it into however your language makes cURL/HTTP requests. In this case with PHP it’s either using the curl functions of a library such as guzzle.
As to code examples
For webhooks - https://github.com/BarryCarlyon/twitch_misc/tree/main/webhooks/handlers/php
For EventSub - https://github.com/BarryCarlyon/twitch_misc/tree/main/eventsub/handlers/php
That covers how to process/secure check incoming messages from Twitch.
And a qucik gloss over your code it looks correct for a creation of a webhook request, without testing it myself. So add some error/debug checking and you can find out the issue/problem