Get twitch stream info
This does not require an application to be registered with Twitch.
Pass the username of the Twitch user you want stream information from inside the msg.topic
input variable.
An example use case for this would be to trigger an automation when a streamer goes live or offline.
The first output will return the information about the stream
{
"data": {
"user": {
"id": "130404073",
"login": "boxyfresh",
"displayName": "BoxyFresh",
"description": "Howdy! I’m just a regular guy that likes to play video games. If i am not live check out my YouTube channel! Stream schedule is posted in discord.",
"createdAt": "2016-07-24T23:23:05.217676Z",
"roles": {
"isPartner": true
},
"stream": {
"id": "48747166957",
"title": "�☠️FIGHTING MALEANDIA TODAY�☠️ TTS 500",
"type": "live",
"viewersCount": 1324,
"createdAt": "2023-06-28T14:22:21Z",
"game": {
"name": "ELDEN RING"
},
"averageFPS": 60,
"bitrate": 4340,
"broadcasterSoftware": "unknown_rtmp",
"codec": "avc1.64002A",
"height": 936,
"width": 1664
}
}
},
"extensions": {
"durationMilliseconds": 59,
"requestID": "01H41D8GV3550Y7JJ79KWDZFC0"
}
}
Data will only come from the second output if the request fails (Twitch returns non 2XX response)
[{"id":"142d2025a21d973e","type":"subflow","name":"Twitch Stream Info","info":"","category":"","in":[{"x":300,"y":300,"wires":[{"id":"79f3d60c029d8c73"}]}],"out":[{"x":820,"y":300,"wires":[{"id":"e0a87695cf018990","port":0}]},{"x":820,"y":360,"wires":[{"id":"4cfd9f692f8bea69","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"79f3d60c029d8c73","type":"function","z":"142d2025a21d973e","name":"build request","func":"\n// function checkIfUserIsStreaming(username) {\n// url = 'https://gql.twitch.tv/gql';\n// query = 'query {\\n user(login: \\\"' + username + '\\\") {\\n stream {\\n id\\n }\\n }\\n}';\n// return true if (requests.request('POST', url, json = { 'query': query, 'variables': {} }, headers = { 'client-id': 'kimne78kx3ncx6brgo4mv6wki5h1ko' }).json()['data']['user']['stream'] else falsealse;\n// }\n\nlet query = `query {\n user(login: \"${msg.topic}\") {\n id\n login\n displayName\n description\n createdAt\n roles {\n isPartner\n }\n stream {\n id\n title\n type\n viewersCount\n createdAt\n game {\n name\t\t\t\t\n }\n averageFPS\n bitrate\n broadcasterSoftware\n codec\n height\n width\n }\n }\n}`;\n\nmsg.payload = {\n 'query': query,\n 'variables': {}\n}\n\nmsg.headers = { 'client-id': 'kimne78kx3ncx6brgo4mv6wki5h1ko' };\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":300,"wires":[["e0a87695cf018990"]]},{"id":"e0a87695cf018990","type":"http request","z":"142d2025a21d973e","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://gql.twitch.tv/gql","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":true,"headers":[],"x":610,"y":300,"wires":[[]]},{"id":"ecc8b0c60563d543","type":"comment","z":"142d2025a21d973e","name":"Fetch twitch stream info for given username","info":"Found some great graphQL examples for Twitch here:\nhttps://github.com/mauricew/twitch-graphql-api/blob/master/USAGE.md","x":470,"y":240,"wires":[]},{"id":"4cfd9f692f8bea69","type":"catch","z":"142d2025a21d973e","name":"","scope":["e0a87695cf018990"],"uncaught":false,"x":610,"y":360,"wires":[[]]},{"id":"34f8af1a778cfd13","type":"subflow:142d2025a21d973e","z":"eb66dfe2.2e006","name":"","x":450,"y":4200,"wires":[["628a4f8232bc60a3"],[]]},{"id":"36cbe50778f657cb","type":"inject","z":"eb66dfe2.2e006","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"koniiiik","x":250,"y":4200,"wires":[["34f8af1a778cfd13"]]},{"id":"628a4f8232bc60a3","type":"debug","z":"eb66dfe2.2e006","name":"debug 37","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":4200,"wires":[]}]