# Cannot send PubSub from EBS

**URL:** <https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267>\
**Category:** Extensions\
**Created:** [July 3, 2022, 3:19am UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267 "2022-07-03T03:19:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TBC1](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/tbc1/32/18813_2.png) [@TBC1](https://staging-discuss.dev.twitch.com/u/TBC1)\
**Post date:** [July 3, 2022, 3:19am UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267/1 "2022-07-03T03:19:27Z")

</div>

I am trying to send a PubSub message from a PHP EBS. Using the documentation at [Reference | Twitch Developers](https://dev.twitch.tv/docs/api/reference) and a php-jwt library, I came up with the following code to create the payload.

```auto
$jwt = new JWT(base64_decode(SOTD_SECRET), 'HS256', 3600, 10);
$token = $jwt->encode([
'exp' => $exp,
'user_id' => $userID,
'channel_id' =>$broadcasterID,
 'role'=>'external',
 'is_linked'=>'true',
 'pubsub_perms'=>['send'=>['broadcast']]
 ]);

```

The secret is from Extension Secrets under Extension Client Configuration.  
I have used several online jwt “testers” and and I am confident that the token is created and signed correctly.

I’m using the following code to send the post.

```auto
$message="refreshLeaders";	
$body=json_encode(["broadcaster_id" => $broadcasterID,'message' => $message,'target' => ['broadcast'],])	;
$curl = curl_init($url);
mylog("Body: $body");
$url='https://api.twitch.tv/helix/extensions/pubsub/';
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array( 'Authorization' => 'Bearer ' . $token, 'Client-ID' => SOTD_CLIENT_ID, 'Content-Type' => 'application/json');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$resp = curl_exec($curl);
curl_close($curl);
mylog("Response from Send Message: ".$resp);

```

The Client ID is the extension client ID  
The response I get is {“error”:“Unauthorized”,“status”:401,“message”:“OAuth token is missing”}. This seems strange since the documentation clearly states " Authorization - Signed JWT created by an Extension Backend Service (EBS), following the requirements documented in [Signing the JWT]".

I’ve tried different combinations of client id and secrets. I’ve tried opaque\_user\_id instead of user\_id. I’ve tried different combinations for target.  
I’ve read as much documentation as I could find, as well as any forum posts on the topic. I cannot figure out what I’m doing wrong.

---

<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:** [July 3, 2022, 11:21am UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267/2 "2022-07-03T11:21:25Z")

</div>

> [@TBC1](#):
>
> `$url='https://api.twitch.tv/helix/extensions/pubsub/';`

The URL is

`https://api.twitch.tv/helix/extensions/pubsub`

Not

`https://api.twitch.tv/helix/extensions/pubsub/`

> [@TBC1](#):
>
> ```auto
> $token = $jwt->encode([
> 'exp' => $exp,
> 'user_id' => $userID,
> 'channel_id' =>$broadcasterID,
> 'role'=>'external',
> 'is_linked'=>'true',
> 'pubsub_perms'=>['send'=>['broadcast']]
> ]);
> 
> ```

You don’t need `'is_linked'=>'true',`

And make sure both the `user_id` and `channel_id` are strings not integers

So

```php
$userID = '123123';

```

Not

```php
$userID = 123123;

```

---

<div class="post-metadata">

**Author:** ![TBC1](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/tbc1/32/18813_2.png) [@TBC1](https://staging-discuss.dev.twitch.com/u/TBC1)\
**Post date:** [July 3, 2022, 4:23pm UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267/3 "2022-07-03T16:23:05Z")

</div>

> [@BarryCarlyon](#):
>
> The URL is
> 
> `https://api.twitch.tv/helix/extensions/pubsub`

The trailing backslash was a BIG issue. I usually find details like that, but missed it… over and over. Thank you.

Debugging as I type this, so… rubber ducky

‘is\_linked’ is gone.  
user\_id and channel\_id were both strings, but I re-cast them anyway to be certain. (verified at [jwt.io](http://jwt.io))  
Now the response is {“error”:“Unauthorized”,“status”:401,“message”:“jwt token is required”}  
Checked expiration. “exp” is +1 hour. (verified on [jwt.io](http://jwt.io))  
I have tried without base64\_decodeing the secret. Same error so I changed it back.  
I re-wrote the header and found two errors. No colon and no space after Authorization.  
New error is {“error”:“Unauthorized”,“status”:401,“message”:“Client ID is missing”}.  
Of course it’s missing. Same reason. No colon and no space: Same with Content-Type. I changed the header creation to

```auto
$headers = array( 
			'Authorization: '.'Bearer ' . $token,
			'Client-ID: ' . SOTD_CLIENT_ID,
			'Content-Type: ' .'application/json');

```

Problem solved and the message is being recieved by the extension.  
Thank you again! This has caused me uncounted hours of grief.

---

<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:** [July 3, 2022, 4:27pm UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267/4 "2022-07-03T16:27:14Z")

</div>

> [@TBC1](#):
>
> New error is {“error”:“Unauthorized”,“status”:401,“message”:“Client ID is missing”}.  
> Of course it’s missing. Same reason. No colon and no space: Same with Content-Type. I changed the header creation to

I got as far as the URL before debugging your actual PHP to spot the header malconstruct 😛

---

<div class="post-metadata">

**Author:** ![TBC1](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/tbc1/32/18813_2.png) [@TBC1](https://staging-discuss.dev.twitch.com/u/TBC1)\
**Post date:** [July 3, 2022, 4:54pm UTC](https://staging-discuss.dev.twitch.com/t/cannot-send-pubsub-from-ebs/39267/5 "2022-07-03T16:54:41Z")

</div>

No worries. I just needed to get past the URL error. The backslash was a leftover from trying the [api.twitch.tv/extensions/message/CHANNELID](http://api.twitch.tv/extensions/message/CHANNELID) endpoint. Feeling doubly ignorant since I recall some time in the past week seeing you mention this exact thing in an older post.  
Off Topic: I tried letting my cat be a rubber ducky, but he just walks away.
