Watch2Gether API Documentation

Watch2Gether provides a simple API that allows you to programmatically create new rooms and update existing rooms.

If you don’t have a Watch2Gether account yet, sign up here first: Watch2Gether - Watch Videos together

The required API key can be generated in you account settings.
Login to your account > “Edit Profile” on the right > At the bottom “New” to generate a new key.

Please note: We recently changed the hostname of our API endpoint from w2g.tv to api.w2g.tv - please update your code!

Important: Keep this key private, never share it publically. Use it only server side, never in client side code.

Creating Rooms

All rooms that you create using the key will be owned by the account associated with the key.

You can create a new room by sending a POST request to:

https://api.w2g.tv/rooms/create.json

Please checkout the sample code bellow. Make sure to set the content type of your request to application/json

fetch("https://api.w2g.tv/rooms/create.json", {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "w2g_api_key": "<api_key>",
        "share": "https://www.youtube.com/watch?v=8Wdp35Z-fRs",
        "bg_color": "#00ff00",
        "bg_opacity": "50"
    })
})
.then(response => response.json())
.then(function (data) {
    console.log("W2G: Here is your room! \n https://w2g.tv/rooms/" + data.streamkey);
});

Body parameters:

  • w2g_api_key: Your API key
  • share: The URL of a video that is preloaded in the room
  • bg_color: Background color of the room in HTML notation
  • bg_opacity: Opacity of the background 0 - 100

In return you get a JSON string. The value of “streamkey” can be used to build the URL of the new Watch2Gether room: https://w2g.tv/rooms/{streamkey}

When you open that room, the shared video will be preloaded.

Updating Rooms

The API allows you to update existing rooms as well.

The “streamkey” in the following examples is the same string as returned from the create method above. It’s also visible in a room’s URL. For https://w2g.tv/rooms/myroom-1234567890abcd the key would be 1234567890abcd

The API user used for the request has to be a member of the room in question. Other rooms can not be updated.

Sharing an Item

The following example shares a new item to a room to be played immediately:

fetch("https://api.w2g.tv/rooms/{streamkey}/sync_update", {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "w2g_api_key": "<api_key>",
        "item_url" : "https://www.youtube.com/watch?v=dMH0bHeiRNg" 
    })
});

Body parameters:

  • w2g_api_key: Your API key
  • item_url: A valid https URL to the item you want to share.

Add to Playlist

The following example adds an item to the active playlist in a room:

fetch("https://api.w2g.tv/rooms/{streamkey}/playlists/current/playlist_items/sync_update", {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "w2g_api_key": "<api_key>",
        "add_items": [{"url": "https://www.youtube.com/watch?v=dMH0bHeiRNg", "title": "Hello World"}]
    })
});

Body parameters:

  • w2g_api_key: Your API key
  • add_items: An array or URLs you would like to add (max 50 at once)
3 Likes

Hey is it possible to add the feature to set the room color and gradient to this api as an optional field?

Cool idea… yes that should be possible quite easily. Will have a look later.

And i have an second idea: Because the api key is now linked with my account is it possible to link the username and/or profile picture also? (So in the channel members its not a “User-randomstring”) Or to hide the creator if its created via API?

You can now set the background color and opacity in the API call.

1 Like

Spelling: “programmatically”, not “problematically”.

Thanks a lot! I just fixed it. That does really make a difference :slight_smile:

2 Likes

How do I get the api key?

It’s explained above in the first post!

What is the name of the library?

Is there possible to make a room timeout"able" if no one joins = if someone “spams” for example the command in the discord bot that these dont clump Watch2Gether :slight_smile:

If not, can be a option for that?

Is the “share” attribute broken? I tried different links, but whenever I create a new room, the link in the “share” attribute is ignored and a random video is loaded.
If “share” is not broken, I will create an extra thread for trouble shooting.

1 Like

Sorry for the late reply. The option generally works and is in use by some internal tools as well. I assume that your request is not properly formatted.

Hi, I tried your method but doesn’t work.

I tried this:

fetch('https://w2g.tv/rooms/create.json', {method: 'POST', 
  body: { 
    "w2g_api_key" : "key",
    "share" : 'https://www.youtube.com/watch?v=bJqJKAoUWkU',  // URL of the video to share - optional
}});

and it returned me the streamKey but it created a random room but no with my video. Thanks

1 Like

Check if the video at all could be played in watch2gether

Yes I can, I tested some videos and no one works

1 Like

You have ‘link’ instead of “link” <-- thats probably the problem

Nah, same problem, tested in my app and postman

and you have a “,” afterthat but that is the last argument that has normaly no “,”