Watch2Gether API Documentation

Hey, I wonder if there is any endpoint to edit a room? I do want to change the url of the current video that is playing and always creating a new room isn’t something I want to do since users would have to share the room link everytime the video changes :confused:

You mean you want to load a new video? Currently there is an internal API but i would not consider it stable enought to be used by external apps. I hope this can the changed soon.

I love the idea of being able to use an API command to queue a video in an existing room. My community has a shared Watch2Gether room that we use to watch videos together. The benefit to being able to queue videos in this room, as opposed to having our bot create a new room every time, is that both general and individualised settings, such as volume, does not have to be changed every time. Is it possible to add such a feature to the API? it would certainly be much appreciated in our community.

@user_4a9fe9cdc8bcb20, @user_6bb3964e87de71d It’s now possible to programtically share items to exisiting rooms. Please check out the updated docs at the top.

2 Likes

I absolutely love this feature, thank you for taking the time to implement it!

One question though, I keep getting a 403 (forbidden) reply for any requests that share items to existing rooms, even rooms that the bot user owns. I’m still able to programmatically create new rooms successfully though.

I’m a hobby programmer so I only dabble in code occasionally, as such, it is very possible that I have overseen some essential steps somewhere. I included my relevant python code below so that it is easier for anyone who can help me with this to judge this.

async def watch(self, ctx, url, *, streamkey="new", background="#000000", bg_opacity="100"):
      if streamkey == "new":
            headers = {
                       'w2g_api_key': watchTogether_api_key, 
                       'share': url,
                       'bg_color': background, 
                       'bg_opacity': bg_opacity
            }
            r = requests.post(url='https://w2g.tv/rooms/create.json', data=headers)
            response = r.json()
            roomkey = response['streamkey']
      else:
            headers = {
                          "w2g_api_key": watchTogether_api_key,
                          "item_url": url
            },
            requests.post(url=f"https://w2g.tv/rooms/{streamkey}/sync_update", data=headers)

Again, this is only part of the code and I’m a hobby programmer so this code is in no way optimised and could be broken by a user quite easily, but I wrote it quickly just to check whether everything was working and if I understood everything correctly… which it seems I do not :laughing: Thanks in advance for any help! :grinning_face_with_smiling_eyes:

Thanks for your feedback. Are you sure that you are passing the correct streamkey to your function? It should only be a 18 character string. Please ensure as well, that the content-type header of your request is set to “application/json”.

1 Like

Hi @user_95f53b7185f71fb :slight_smile: Is there a possibility to add a video to the playlist via the api instead of playing it directly? :slight_smile:

Thanks for your work

1 Like

Not yet, but we are working on it :slight_smile:

1 Like

Queuing videos would be great for using the api in a discord bot.

I made a easy to use client in typescript for interacting with the api

And queueing would be a great addition to that

Thanks a lot for you effort! Queuing is on the todo list. I requires a bit more work since the client needs to know to which playlist an items should be added.

Ok, I finally found the time to sit down and look at this issue again. For anyone facing the same issue with a 403 response I’ll post what I did here. In short, I switched from using the python Requests package to using the urllib package, which seems to have done the trick.

Everything above the ‘else’ statement is the same as I posted above so I’ll just skip that here. It might also be important to note that you need to import both ‘request’ and ‘parse’ from urllib. For some reason, however, I also had an issue importing ‘request’ from urllib so I just didn’t bother with it and imported the whole urllib package.

else:
    payload = {
            "w2g_api_key": watchTogether_api_key,
            "item_url": f"{url}"
    }

    # HTTP request using urllib
    data = urllib.parse.urlencode(payload).encode()
    req = urllib.request.Request(f"https://w2g.tv/rooms/{streamkey}/sync_update", data=data) # this will make the method "POST"
    resp = urllib.request.urlopen(req)
    print(resp.code)
1 Like

Thanks for sharing this!

1 Like

@user_95f53b7185f71fb Hello there!

I gotta ask you bout a ‘feature’ that I found coding bot for Telegram. What is the purpose of verifying user with cookies and api_key instead of choosing only api_key? Second question is why every new room is created by a random user, not the one connected with api_key?

Any plans to allow player controls (pause/play, skip forward x mins, etc) via API call? Would be useful for something I’m writing.

1 Like

I assue that you are not posting the api_key parameter correctly. The correct name is “w2g_api_key”. If the parameter is not included in the right a way a random anonymous user is created to perform the request.

There are plans to allow 3rd parties to develop custom apps that run within Watch2Gether. More infos soon.

1 Like

Okay, you should include that information in upper docs I guess. Thanks tho!

1 Like

How do I add videos to an existed playlist with this API?

Hi! This is officially not yet possible since there needs to be a way to browse and address a specific playlist first. But it’s on the todo list!

I will make a Python script for that so it will take probably 3-4 hours to make it workable and I will share it on a git site