Hi all,
just a quick question, I’m trying to send a PubSub message from a backend service using the developer rig on localhost but I’m getting 401 errors back. I don’t seem to have a numeric channel so I’m POSTing to the channel name (which I think should be fine):
https://api.twitch.tv/extensions/message/rignitro_marky
this is the request code I’m using:
var options = {
url : 'https://api.twitch.tv/extensions/message/rignitro_marky',
headers :{
'Authorization' : 'Bearer ' + signedJwt,
'Client-ID': 'g39equtxkqd9z7s9qvj6cshk8',
'Content-Type': 'application/json'
},
body : JSON.stringify({
message: payload,
content_type: 'application/json',
targets: ['broadcast']
})
};
function details(error,response,body)
{
console.log(body);
}
request(options, details);
I’m clearly missing something fundamental so if anyone has any ideas that would be great
Mark
Just to clarify, I’m using NodeJS and the JSONWebToken library and creating the token the usual way
let signedJwt = jwt.sign(Payload, currentSecret);
I can now send a pubsub message for an extension but am getting a 204 error (no content), where is the content supposed to go?? I’m using the example given and am getting the error.
var dataToSend = {"content_type":"application/json", "message":"{\"foo\":\"bar\"}", "targets":["broadcast"]};
//dataToSend = JSON.stringify(dataToSend);
$.ajax({
url: 'https://api.twitch.tv/extensions/message/178080165',
headers: {
'Authorization':'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODkzNDg5NDcsInVzZXJfaWQiOiIxNzgwODAxNjUiLCJyb2xlIjoiZXh0ZXJuYWwiLCJjaGFubmVsX2lkIjoiMTc4MDgwMTY1IiwicHVic3ViX3Blcm1zIjp7InNlbmQiOlsiKiJdfX0.GTUWnBKwtei6-j2OYh6R8Fj59m8bDkUmWbxQVTeDs4Y',
'Client-Id':'g39equtxkqd9z7s9qvj6cshka1jgu8'
},
method: 'POST',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: dataToSend,
success: function(data){
console.log(data);
}
});
This is what I’m using.
What did you change in your code to fixed it ?
To be honest, I’m going to make myself look like a right idiot, it was working all along. When I was testing in Postman I was getting 204 errors which started to confuse me until I realised that is the correct response.
Once I had set up a listener I was able to pass the data and log it.
Mark
1 Like
204 YAY it worked, but there is no body response or JSON payload to give you!
Officially:
The server successfully processed the request and is not returning any content
It’s a toss up if it should be a 201 Created, but that would “expect” that something be returned that represents what was created. So 204 is best fit on this end point
Yep, until a listener is set up and then the message is passed through there
Just a basic question (i suppose ^^) :
- What is the right way to obtain the “Payload” you want to sign ?