# How to use webhook for checking users are livestreaming and get there data?

**URL:** <https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694>\
**Category:** API\
**Created:** [February 23, 2023, 4:41am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694 "2023-02-23T04:41:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 23, 2023, 4:41am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/1 "2023-02-23T04:41:05Z")

</div>

how to use webhook for checking users are livestreaming and get there data?how to create webhook url for twitch developers ?

---

<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:** [February 23, 2023, 10:53am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/2 "2023-02-23T10:53:17Z")

</div>

> [@Sharayu\_Faye](#):
>
> how to create webhook url for twitch developers ?

the Webhook you is create by you

it is the URL that data is POSTed to on your server

So when you write the code to consume webhook data, you will decide what URL it will be.

> [@Sharayu\_Faye](#):
>
> how to use webhook for checking users are livestreaming and get there data?

Stream Online is foind her [EventSub Subscription Types | Twitch Developers](https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#streamonline)

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 23, 2023, 12:10pm UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/3 "2023-02-23T12:10:03Z")

</div>

error": “Bad Request”  
+“status”: 400  
+“message”: “missing or unparseable subscription condition”

I’m getting this error on following above flow

---

<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:** [February 23, 2023, 12:15pm UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/4 "2023-02-23T12:15:59Z")

</div>

That suggests your body type didn’t match the header type.

IE you sent a JSON body, but didn’t say you were sending JSON with a header.

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 23, 2023, 1:52pm UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/5 "2023-02-23T13:52:08Z")

</div>

“Accept: application/vnd.twitchtv.v5+json”  
I have added this in header for request

---

<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:** [February 23, 2023, 1:55pm UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/6 "2023-02-23T13:55:08Z")

</div>

Thats not the correct header.  
Thats also the header used with the kraken API which is long dead.

The normal JSON header is

`Content-Type: application/json`

Sure this might work not but it’s not _standards_

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 24, 2023, 6:52am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/7 "2023-02-24T06:52:51Z")

</div>

> [@BarryCarlyon](#):
>
> `Content-Type: application/json`

same error for this one also , how to solve this error ?

---

<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:** [February 24, 2023, 7:28am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/8 "2023-02-24T07:28:55Z")

</div>

What does your code look like to make the request to create a subscription?

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 24, 2023, 10:33am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/9 "2023-02-24T10:33:38Z")

</div>

(post deleted by author)

---

<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:** [February 24, 2023, 10:35am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/10 "2023-02-24T10:35:22Z")

</div>

You declared you were posting JSON  
And then posted a form.

The form layout isn’t correct for POSTing as a form.

It’s easier to send as JSON. So

```php
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($object));

```

Should do the trick rather than `http_build_query`

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 24, 2023, 11:00am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/11 "2023-02-24T11:00:24Z")

</div>

(post deleted by author)

---

<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:** [February 24, 2023, 11:02am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/12 "2023-02-24T11:02:19Z")

</div>

It’s `json_encode(theobject);` not `json_encode('theobject');`

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 24, 2023, 11:14am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/13 "2023-02-24T11:14:41Z")

</div>

above solution is giving syntax error , also I have tried

```php
 curl_setopt($ch, CURLOPT_POSTFIELDS, '{"type":"channel.follow","version":"1","condition":{"broadcaster_user_id":"'.intval($oAuth['data'][0]['id']).'"},"transport":{"method":"webhook","callback":"---","secret":"'.$secret.'"}}'); 

```

this also gives error → The value specified in the method field is not valid

I think this error is regarding with the method in the parameters we are sending

---

<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:** [February 24, 2023, 11:26am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/14 "2023-02-24T11:26:33Z")

</div>

```php
<?php

$client = '';
$token = '';
$user_id= '';
$callback = '';
$secret = '';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/helix/eventsub/subscriptions');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Client-ID: ' . $client,
    'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_POST, 1);

$payload = array(
    'type' => 'stream.online',
    'version' => '1',
    'condition' => array(
        'broadcaster_user_id' => $user_id
    ),
    'transport' => array(
        'method' => 'webhook',
        'callback' => $callback,
        'secret' => $secret
    )
);
print_r($payload);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));

curl_exec($ch);

```

Successfully created a subscription request for me

Edit:

Earlier I copy/pasted your “broken header” but didn’t notice you put `Accept` where it should be `Content-Type`

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 24, 2023, 11:31am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/15 "2023-02-24T11:31:21Z")

</div>

Thanks

---

<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:** [February 27, 2023, 8:14am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/17 "2023-02-27T08:14:03Z")

</div>

Using the TwitchCLI the result is

```auto
$ twitch event verify-subscription cheer -F https://dev.clickitfame.com/twitch/webhook/callback
✗ Invalid response. Received <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<p>Additionally, a 401 Unauthorized
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
 as body, expected 3aa60148-3314-44b5-27f7-3d644ebf6c9d
✗ Invalid content-type header. Received type text/html with charset iso-8859-1. Expecting text/plain.
✗ Invalid status code. Received 401, expected a 2XX status

```

Your server cannot be reached due to the basic authentication dialog

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 27, 2023, 9:28am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/18 "2023-02-27T09:28:22Z")

</div>

> [@BarryCarlyon](#):
>
> Your server cannot be reached due to the basic authentication dialog

after remove authentication also same error giving

---

<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:** [February 27, 2023, 9:29am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/19 "2023-02-27T09:29:21Z")

</div>

```auto
% twitch event verify-subscription cheer -F https://dev.clickitfame.com/twitch/webhook/callback | more
✗ Invalid response. Received <!doctype html>
<html class="theme-light">
<!--
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The POST method is not supported for this route. Supported methods: GET, HEAD. in file /home2/clickit9/public_html/oguzhan-clickitfame/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php on line 117

SNIP

 as body, expected 6b4592bb-7dfe-480a-8561-6c76d14e3f8a
✗ Invalid content-type header. Received type text/html with charset UTF-8. Expecting text/plain.
✗ Invalid status code. Received 405, expected a 2XX status

```

Something isn’t grabbing and processing the POST request correctly.

You can download and use the CLI to test yourself - [Twitch CLI | Twitch Developers](https://dev.twitch.tv/docs/cli/)

---

<div class="post-metadata">

**Author:** ![Sharayu\_Faye](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/sharayu_faye/32/22835_2.png) [@Sharayu\_Faye](https://staging-discuss.dev.twitch.com/u/Sharayu_Faye)\
**Post date:** [February 27, 2023, 9:36am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/20 "2023-02-27T09:36:52Z")

</div>

yes I have tried but unable to install  
scoop in windows

---

<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:** [March 29, 2023, 9:37am UTC](https://staging-discuss.dev.twitch.com/t/how-to-use-webhook-for-checking-users-are-livestreaming-and-get-there-data/43694/21 "2023-03-29T09:37:31Z")

</div>

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