Connecting to the API and getting data from Channel Points Rewards

Hey :slight_smile:

When a viewer is redeeming a custom channel point reward, I would like to get the information of “Who redeemed which CP Reward?”. It seems to be that I get this info from the Channel Points Custom Reward Redemption Add Notification. But I am already having troubles with getting connected to the twitch API. I am working with nodeJS and for example when I try to connect with the streamlabs API, all I need to do is:

~ register app on streamlabs
~ take the Socket API Token and create a windows environment variable
~ install
~ and then just write this 3 lines:

const io = require('');
const streamlabs = io(`${process.env.STREAMLABS_SOCKET_API}`, {transports: ['websocket']});
streamlabs.on('connect', () => console.log('Connected with Streamlabs.'));

After those steps, I can get information from things like Test Subs. But this easy way is not mentioned in the streamlabs dev docs. And looking into the twitch dev docs makes it again more complicated than easy (I could rant SO MUCH about how user/beginner unfriendly these docs are written, but that would be too much text and not help here :laughing:).
So I have this feeling there MUST be also an almost equal simple way to connect to the twitch API like with the streamlabs API. But how?
Steps I have already taken is to register an app on twitch, so I already have a Client ID and a Client Secret. And as mentioned above, nodeJS and are installed.

What are the next steps? :slight_smile:

EventSub is (currently) a webhook only mechanism

You need a server (such as running express for example, since we are talking node).
That is capable of recieving HTTP post requests

A regular eventsub example

A more channel points specific event sub example

For a socket solution, you want to be talking to the channel-points topic on pubsub

I have no issue, the docs list the endpoints and the response to those endpoints.

Everything else I throw tests/requests at and see what comes back.

What specifically is complicated in the docs? Feedback is always being gathered to improve the documentation.

You need a server (such as running express for example, since we are talking node).
That is capable of recieving HTTP post requests

Ok, express is installed now.

A more channel points specific event sub example

So this is what I have to use to test the finished code for channel points rewards?

What specifically is complicated in the docs?

Well the first thing is, that the code examples are just written in one langage, which seems to be called cURL. As soon as a reader doesn’t know this language (like me), it gets confusing. Streamlabs has a refernce website with 5 different languages. That does not mean, that a js-idiot like me immediatly understands it, but atleast the chances are higher that I can find it out by looking at my language and also the others. E.g. when I looked into the twitch dev docs for my problem, first I looked into Twitch API. But the first code that I see there is this:

curl --location --request
GET '' \
--header 'client-id: wbmytr93xzw8zbg0p1izqyzzc5mbiz' \
--header 'Authorization: Bearer 2gbdx6oar67tqtcmt49t3wpcgycthx'

That’s not helpful.

The second thing is, that the docs don’t give enough information. So for example: As mentioned at the start post, I would like to connect to the twitch API and get the CP reward infos. You are so nice and help me by saying “Better you look into PubSub”. So I look into PubSub and the info it gives me is “A PubSub is [explaination].” and “The content of a PubSub is [list of content]”. But there is no “And THIS is how you get the content.”. All I see is “Something, something wss://, ping, pong, listen, reconnect” and “Not that important, but good to know”-info like the API Limits. And this way of giving information basicly goes through the whole dev docs. There are no examples of “Here is the summarizing example code for this topic. In chase you want to copy-paste it, there are [EXAMPLE] fields. E.g. one info you need is your Client ID. So look for [EXAMPLE Client ID], delete it including the [], and write you Client ID.”

So all in all the dev docs are written in a way, that feels like you have to be the programmer who programmed all of twitch and with that understand 100% of EVERY single word in it. I mean, of course this site is made for people who know what it is about. And I am just a stupid beginner. But how much it is just assuming that you should know and also remember is really user unfriendly. Just look at my short explaination of how I connect to streamlabs: 4 steps and just 3 lines of code. That’s all. Why is it so hard to put such examples into the twitch dev docs? The dev docs just makes me feel dumb by reading it, annoyed by being forced to ask for help again, and angry that I have to waste somebody else time by answering my stupid question.

Ok, enough of this little rant. Sorry for the text block, it’s just all so exhausting with how hard it is, especially when it could be way easier.
It’s late here now and I go to bed. See you tomorrow. Good night and thanks for helping me (or more like “trying to help” because I am an idiot).

This tells you the

  • HTTP Method, it’s GET
  • the URL to call
  • you need two headers, a client-ID header and and Authorization

(--location --request and superflous, and some of the newer docs, the doc writer has been using the “longer” form of the cURL flags/arguments)

This is then translatable into any langauge, Streamlabs does 5, well what about the others, such as PHP or brainfuck or lua for example?

Aside from being opinated on the languages, SL also is opnatiated on the libraries to use, like nodeJS they suggest you use node-fetch

Which means you learn to use node-fetch instead. As then we’ll get questions like “I’m trying to do this in axios/got/other module/no module at all”. So cURL is given as a cURL call can be translated to match whatever language you are working in and whatever module/library you are working with.

Which is why cURL is the first example in the Streamlabs docs, as cURL is universal

Given that all of Twitch’s offerings (except kraken) requires an oAuth token to do anything, you can’t just copy paste without getting a token first, so you can’t really do “simple” copy/pasta examples

cURL is “standard” and language agnostic.

Most lanaguaages generally just implement cURL under the hood and provide helper libraries to convert to cURL. So the Twitch docs are unopinated on langauge.

Not really thats, “heres how to use nodeJS library of socket IO to connect” it’s an “opinated” piece of documetnation that says “you should be using nodeJS”.

It’s four steps of “heres just use that”, (granted they are using a server). So the ways to connect to are limited, to the langauges that has been ported to. Twitch uses websockets (which uses underneath), and websockets can be made to work much more easily in any langauge, and thus the docs don’t give an opinion on language or modules to use.

Twitch’s docs tell you the endpoints you can call and the responses to those endpoints, so it doesn’t say use as thats an opinion on what you should use, as apposed to “heres the calls, use what you are used to using”

The only stupid question is the one you don’t ask.

Of course this is all irrelevant if instead of reading the docs, you use someone elses Twitch library (for nodeJS if you stay in node), as then you follow their docs for their library instead.

Feel free to use any module that can recieve HTTP Posts requests, I use express myself, so use what you are comfortable with, and you don’t have to use NodeJS.

For channel points first you need an access token (with the relevant scopes attached) to a channel that has channel points enabled, which is affiliate+

Feel free to use any module that can recieve HTTP Posts requests, I use express myself, so use what you are comfortable with, and you don’t have to use NodeJS.

I found a solution that uses the https module, because it is already in node.

For channel points first you need an access token (with the relevant scopes attached) to a channel that has channel points enabled, which is affiliate+

The mentioned solution looks like this…

const https = require('https');
const options = {
  host: '',
  path: '/oauth2/token?client_id=[myClientID]&client_secret=[myClientSecret]&grant_type=client_credentials&scope=channel:read:redemptions',
  method: 'POST',

callback = function(response) {
  let str = '';
  response.on('data', function (chunk) {
    str += chunk;
  response.on('end', function () {
https.request(options, callback).end();

…which gives me this…


So I have an access token now, but:
1.1 My channel has NOT channel points enabled. Can I still make tests?
1.2 If yes, I should use your twitch misc aboutchannel points then?
2.1 The PubSub says, I need a constant connection to the topic with LISTEN, PING and wss:// Do I have to do that with this?
2.2 If yes, how would it look like combined with twitch? Something like this?

const https = require('https');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Connected with topic.');

2.3 If no, what would be the right code?

No, as the API will reject reward creation

That is a rough clone of some production code I use for 2/3 channels (2 live one in dev)

No, the example you link to is for recieving HTTP, not for connecting to PubSub.

I have a PubSub example here

No this shows a misunderstanding of what PubSub is. Pubsub is a socket connection where you conenct to a server maintain. Not a server where someone else send you data

It is not dissimilar from the Streamlabs example, but you have to create the connection managment logic/maintaince. See the pubsub nodejs example I linked.

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