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)