# \[Resolved\] Webhook sub accepted but not receiving events

**URL:** <https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570>\
**Category:** API\
**Created:** [March 2, 2018, 7:50pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570 "2018-03-02T19:50:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 2, 2018, 7:50pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/1 "2018-03-02T19:50:52Z")

</div>

Just starting out using webhooks in php and I can’t seem to get any events POSTs from Twitch. I’m able to successfully subscribe with a 202 code and I believe I’m responding to the challenge by doing:

echo $\_GET[‘hub\_challenge’]

Lease seconds has a value in the GET request so I know that isn’t 0 and I’ve checked the callback and it seems to be working correctly when I do a test POST. I’m not really sure where to look into now.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![george](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/george/32/120_2.png) [@george](https://staging-discuss.dev.twitch.com/u/george)\
**Post date:** [March 2, 2018, 10:44pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/2 "2018-03-02T22:44:19Z")

</div>

Check your web server access logs to see if Twitch is even attempting to send the POST. If you see the request there than there is probably an issue with your code receiving the POST.

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 2, 2018, 11:15pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/3 "2018-03-02T23:15:26Z")

</div>

I don’t see any post requests made by Twitch. The only ones I see are the ones I make when subscribing to an event.

---

<div class="post-metadata">

**Author:** ![Syzuna](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/syzuna/32/3750_2.png) [@Syzuna](https://staging-discuss.dev.twitch.com/u/Syzuna)\
**Post date:** [March 3, 2018, 12:33am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/4 "2018-03-03T00:33:36Z")

</div>

Try 200 Statuscode instead of 202. Iirc there was a bug or sth

Or is the 202 from twitch?

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 3, 2018, 12:41am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/5 "2018-03-03T00:41:46Z")

</div>

202 is from Twitch. I believe 200 is default for php?  
Should I be echo-ing the status code back?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 3, 2018, 12:57pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/6 "2018-03-03T12:57:06Z")

</div>

What topics did you subscribe to?

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 3, 2018, 7:34pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/7 "2018-03-03T19:34:09Z")

</div>

Just the new followers one.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 4, 2018, 12:02pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/8 "2018-03-04T12:02:25Z")

</div>

Whats the full topic URL?

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 4, 2018, 11:14pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/9 "2018-03-04T23:14:50Z")

</div>

Testing with this one right now: [https://api.twitch.tv/helix/users/follows?first=1&to\_id=23161357](https://api.twitch.tv/helix/users/follows?first=1&to_id=23161357)

The get request from Twitch:  
Key: hub\_challenge Val: Xi77C2JObkMIRmwCraeU3\_AQyxUcdfwMuJXD60lN  
Key: hub\_lease\_seconds Val: 86400  
Key: hub\_mode Val: subscribe  
Key: hub\_topic Val: [https://api.twitch.tv/helix/users/follows?first=1&to\_id=23161357](https://api.twitch.tv/helix/users/follows?first=1&to_id=23161357)

And I’m echoing “Xi77C2JObkMIRmwCraeU3\_AQyxUcdfwMuJXD60lN” in this case.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 4, 2018, 11:45pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/10 "2018-03-04T23:45:34Z")

</div>

Hmmm seems all should work.

Can you post your whole PHP handler with the secrets removed?

Is weird you are not seeing the posts in your server access log though…

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 5, 2018, 4:20am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/11 "2018-03-05T04:20:33Z")

</div>

```
<?php

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers:*");
ini_set("allow_url_fopen", true);

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    
    $printString = "";
    
    foreach ($_GET as $key => $value) {
        
        $printString = $printString . "Key: " . $key . " Val: " . $value . "\n";
    }
    
    file_put_contents("getRequest.txt", $printString);
    
    if (isset($_GET['hub_challenge'])) {
        $challenge = $_GET['hub_challenge'];
        echo $challenge;
    }
}
    
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $payload = "POST received\n";
    //$payload = file_get_contents('php://input');
    file_put_contents("payload.txt", $payload);
}

?>

```

There’s not much going on in the handler right now. I’m just writing to a file to see if a request is coming through.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 5, 2018, 10:14am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/12 "2018-03-05T10:14:57Z")

</div>

And what about the code making the subscription request?

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 5, 2018, 6:15pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/13 "2018-03-05T18:15:54Z")

</div>

```
<?php
require "site.class.php"

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers:*");

$app = new site('');

$mode = $_POST['submode'];
$client_id = <client id>;
$lease_seconds = 24*60*60;

$postData = array(
    'hub.mode' => $mode,
    'hub.topic' => "https://api.twitch.tv/helix/users/follows?first=1&to_id=23161357",
    'hub.callback' => '<website>/PHP/webHookHandle.php',
    'hub.lease_seconds' => $lease_seconds,
);

$dataEncode = json_encode($postData);

$httpHeader = array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($dataEncode),
    'Client-ID: ' . $client_id
);

$app->bufferPost("https://api.twitch.tv/helix/webhooks/hub", $dataEncode, $httpHeader);

?>

public function bufferPost($link, $postField, $httpHeader) {
        curl_setopt($this->curl, CURLOPT_VERBOSE,true);
        curl_setopt($this->curl, CURLOPT_URL, $link);
        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $this->userAgent);
        
        curl_setopt($this->curl, CURLOPT_POST, true);
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postField);
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $httpHeader);
        
        //turn off HTTPs errors
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
        
        //where cookies are saved if cookie exists
        if ($this->cookieFile) {
            curl_setopt($this->curl, CURLOPT_COOKIESESSION, TRUE);
            curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieFile);  
        }
        
        curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);
        curl_setopt($this->curl, CURLOPT_REFERER, $this->referer);
        
        $this->bufferPage = curl_exec($this->curl);
        $httpCode = curl_getinfo($this->curl , CURLINFO_HTTP_CODE);
    }

```

That should cover everything for the subscription part.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 5, 2018, 6:39pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/14 "2018-03-05T18:39:02Z")

</div>

Ok I think I know the issue

In your handler:

> if ($\_SERVER[‘REQUEST\_METHOD’] === ‘GET’) {

Add a

> file\_put\_contents(“getRequestHeaders.txt”, getallheaders());

And get the contents:

I bet you are getting

> ‘hub.topic’ =\> "[https://api.twitch.tv/helix/users/follows?first=1](https://api.twitch.tv/helix/users/follows?first=1)

instead of

> ‘hub.topic’ =\> "[https://api.twitch.tv/helix/users/follows?first=1&to\_id=23161357](https://api.twitch.tv/helix/users/follows?first=1&to_id=23161357)

If so you need to change your postData as follow:

```
$postData = array(
    'hub.mode' => $mode,
    'hub.topic' => "https://api.twitch.tv/helix/users/follows?first=1&amp;to_id=23161357",
    'hub.callback' => '<website>/PHP/webHookHandle.php',
    'hub.lease_seconds' => $lease_seconds,
);

```

And retest

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 5, 2018, 7:46pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/15 "2018-03-05T19:46:51Z")

</div>

This is what I’m getting from getallheaders()

Key: Content-Length Val: 0  
Key: Accept-Encoding Val: gzip  
Key: Connection Val: close  
Key: User-Agent Val: Go-http-client/1.1  
Key: Host Val:

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 5, 2018, 9:11pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/16 "2018-03-05T21:11:14Z")

</div>

Hmm weird.

Check all the passed $\_GET vars?

Also try the `&amp;` fix and see if that works 🙂 (I still need to move from the old topic to the new myself…)

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 5, 2018, 9:58pm UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/17 "2018-03-05T21:58:38Z")

</div>

Yup, the $\_GET vars look correct.

Using & returns a 400 code when trying to subscribe to the topic.

---

<div class="post-metadata">

**Author:** ![Ltcellis](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltcellis](https://staging-discuss.dev.twitch.com/u/Ltcellis)\
**Post date:** [March 6, 2018, 12:25am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/18 "2018-03-06T00:25:19Z")

</div>

I figured it out. It was an issue with echo-ing the challenge back. Turns out there was an extra space/newline at the end of the echo.

Now I feel silly. 🙃

Thanks for all the help.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 6, 2018, 8:44am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/19 "2018-03-06T08:44:50Z")

</div>

Ha!

Glad to have helped and we got it sorted!

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [April 5, 2018, 8:45am UTC](https://staging-discuss.dev.twitch.com/t/resolved-webhook-sub-accepted-but-not-receiving-events/14570/20 "2018-04-05T08:45:07Z")

</div>

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