Get Room UUID via C#

I am primarily a C# developer, I see in the documentation that if I want to have a chat bot join a custom room on my channel it needs to be through the room UUID.

It also says that to get this room uuid I can use the Get Chat Rooms by Channel endpoint. The sample code looks to be in some sort of Java that returns the info as JSON data.

My question is how could I achieve this same request with C#?

The API is just HTTP requests. So just google for a HTTP library/module for your language, C# in this case, and send a request with the URL/headers specified in the docs. The result is JSON, so you’ll have to parse that into whatever data structure is appropriate.

1 Like

Thank you @Dist, I was able to find examples of this in C#.

For instance, for me to send a request to the Root URL like is shown under the Requests section at https://dev.twitch.tv/docs/v5

The block of code that worked for me was as follows:

private const string TWITCH_ENDPOINT = “https://api.twitch.tv/kraken/”;
public void SendRequest() {
WWWForm form = new WWWForm();
Dictionary<string, string> headers = form.headers;
headers[“Accept”] = “application/vnd.twitchtv.v5+json”;
headers[“Authorization”] = “OAuth [My OAuth token without the brackets]”;

    WWW request = new WWW(TWITCH_ENDPOINT, null, headers);
    StartCoroutine(OnResponse(request));

}

private IEnumerator OnResponse(WWW req) {
yield return req;
print(req.text);
}

That works fine, and the response I got back is in the same format as the documentation shows. However, when I modified this to get the room UUID, adding in the Client-ID header, and changing the endpoint string to ‘https://api.twitch.tv/kraken/chat/thatchcastle/rooms’ the response is {"_total":0,“rooms”:[]}.

I made an extra room while testing this, so I expected to see either one or two rooms in the response, any thoughts on why it’s coming back zero?

The reason it’s showing 0 rooms is because you’re using the Channel Name in the URL when v5 uses channel ID. So your request is working but it’s requesting for a channel that doesn’t exist.

If you use your ID instead the URL will be https://api.twitch.tv/kraken/chat/176636611/rooms which correctly shows the room.

1 Like

Why yes it does! Thank you again for all your help!

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