I’ve done some changes as you suggested but it’s still giving me the same error.
This is what i have now:
function sendContributionBroadcast(contributor) {
console.log("sending contribution broadcast");
const channelId = contributor.channel;
const token = makeServerToken(channelId);
const headers = {
'Client-ID': i,
'Content-Type': 'application/json',
'Authorization': `Bearer: ${token}`
};
const body = JSON.stringify({
content_type: 'application/json',
message: JSON.stringify(contributor),
targets: ['broadcast']
});
request(
`https://api.twitch.tv/extensions/message/${channelId}`,
{
method: 'POST',
headers,
body
}, (err, res) => {
if (err) {
console.log(err);
} else {
console.log(res);
}
}
);
}
function makeServerToken(channelId) {
console.log(`makeServerToken( channelId: ${channelId} )`);
const serverTokenDurationSec = 60;
const payload = {
"exp": Math.floor(Date.now() / 1000) + serverTokenDurationSec,
"user_id": `${channelId}`,
"channelId": `${channelId}`,
"role": 'external',
"pubsub_perms": {
"send": ['broadcast']
}
};
return jwt.sign(payload, secret);
}