Event Sub Example Not Working

Thanks for that!

Strangely enough, however… and I’m not sure why, but when I access the new index.php it doesn’t even produce the log anymore. Usually, it would produce the log right up until there was an error, then it would simply stop.

I renamed my old file, then did a copy/paste of your code and have ensure that my code is directed toward the new php.

Honestly, I can’t see what would stop it producing any of the logs.

Just changed my code to read the old php file, and the logs were generated again.


Parse error: syntax error, unexpected token “:” in /Users/barrycarlyon/Sites/github/twitch_misc/eventsub/handlers/php/index.php on line 84

That would be the syntax error on line 84 :smiley:

Yup! That was it :slight_smile:
Now, I appear to be getting mismatch regarding the sigs. Is the process of converting all of the headers to lowercase somehow altering the signatures, so they no longer match?

No coz it only changes the key in the header not the contents of the header.

But if I go back to the old php, they match again.

Line 65 is wrong

$twitch_event_timestamp = $headers[‘twitch-eventsub-message-timestam’];

should be

$twitch_event_timestamp = $headers[‘twitch-eventsub-message-timestamp’];

That appears to be the closest so far, but it’s unfortunately sat on pending.

It doesn’t appear to be sending back that challenge.

I added “mylog(‘Success!!!’);” to the log so I can see if it got through, but I’m not seeing the “Returning the challenge” log entry.

if ($our_signature == $twitch_signature) {
    // passes test
    if ($headers['twitch-eventsub-message-type'] == 'webhook_callback_verification') {
        // it's a verification request
        $data = json_decode($raw_data);
        // and check the data parse
        if (json_last_error() == JSON_ERROR_NONE) {
            mylog('Returning the challenge: ' . $data['challenge']); 
            echo rawurlencode($data['challenge']);
        mylog('Failed to parse the JSON to verification');
        echo 'Failed to parse JSON';

Would that suggest it IS finding an error while decoding the JSON?

            if (json_last_error() == JSON_ERROR_NONE) {
                mylog('Returning the challenge: ' . $data->challenge);
                echo rawurlencode($data->challenge);

Forgot that json_decode makes a object not an array by default

tested the script with TwitchCLI both to verify and recv a payload and it seems to be behaving as required now

That did it! Brilliant! Thank you so much!

Hi @ BarryCarlyon,
I’ve looked at your example, as well as many others in online.

So glad to see I’m not the only one with this issue. Meaning, responding to Twitch’s ack of our subscription. Btw, I’m not working in PHP.
When I run the request I get a 404.

I’m looking for a simple request example which specifically states:

  1. Twitch Endpoint
  2. URL Parameter(s)
  3. Headers
  4. Body

Here is what I’m doing:

  1. Endpoint - https://api.twitch.tv/helix/webhooks/callback
  2. URL Parameter - ?status=200
  3. Headers - Client-ID & Authorization
  4. Body - challenge (as a string in raw format)

Please let me know where I went wrong. Thank you in advance!

You get a 404 because that endpoint doesn’t exist.

You seem to be trying to create a new request, when all you need to do is respond to Twtich’s request.

For the Callback verification you respond with the challenge and a 200 status, and for notification responses you just respond with a 200.

Don’t do this.

You need to reply to it like you would a website login to your website.

  • Someone goes to a page
  • Fills in the login form
  • The users hits login
  • You reply “password ok” or “password invalid”

This works simarily in eventsub

  • You Tell Twitch to make a subscription
  • Twitch fills in a form
  • Twitch hits go
  • You reply with the challenge (from the form) or reject it

In neither of these examples do you make a “second” request to an API.

Can you please give me an example of how you reply with the challenge?

Though this is language depending.

Basically however you output HTML for a webpage in your language of choice

Thank you Barry! I really appreciate your help. I’m a beginner programer in high school.
I understand that we need to reply back to Twitch w/ the challenge. I need some details.
I don’t understand the method of communication.
Also, I don’t know that language. I’m using Go if that helps.

Nevermind, I think I get it. We need to send the challenge in the response to the webhook.
If I’m wrong, please let me know. Thanks again!

That is correct.

You response HTTP 200 with body of the challenge.

Will try. Thank you!

A post was split to a new topic: Eventsub may not trigger

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