Editing a YouTube playlist from code sounds like the simplest thing the API does. Change a title, flip it from private to public, done. It is one call, playlists.update, and it has more ways to quietly go wrong than anything else I have used in the API.
I built TidyList, a web app for cleaning up big YouTube playlists, on the YouTube Data API v3. Its playlist editor changes a playlist's title, description and visibility, as well as its videos in bulk. These three caught me out.
The manual way
On YouTube, you can edit a playlist's title, description and visibility on the playlist's own page, one playlist at a time. Its videos are changed one by one, through each video's menu. Nothing here is hard. It is just slow once there are dozens of playlists or hundreds of videos.
Trap 1: an update replaces the whole snippet
You want to change the title, so you send the title:
// ⚠️ Don't: this clears every snippet field you left out
await http.put(`${base}/playlists?part=snippet`, {
id: playlistId,
snippet: { title: newTitle }
});
It works, and the title changes. It also quietly wipes the description, the tags and the default language, because playlists.update replaces the snippet rather than merging into it. Any mutable field the request leaves out is cleared.
So every update sends back what it isn't changing, taken from the playlist you loaded:
function writableSnippet(edit: { title: string; description: string }, loaded: PlaylistSnippet) {
const snippet: PlaylistSnippet = { title: edit.title, description: edit.description };
if (loaded.tags) snippet.tags = loaded.tags;
if (loaded.defaultLanguage) snippet.defaultLanguage = loaded.defaultLanguage;
return snippet;
}
Nothing fails when you get this wrong. The user just finds their tags gone, much later, with no idea why.
Trap 2: changing visibility still needs the snippet
Visibility lives in status.privacyStatus (private, unlisted or public), so it looks like a job for part=status alone. YouTube refused that for me with 400 unexpectedPart.
What works is sending both parts: the loaded snippet unchanged (built with the same function as above, since snippet.title is required on every update) and a status holding only the new privacyStatus:
await http.put(`${base}/playlists?part=snippet,status`, {
id: playlistId,
snippet: writableSnippet({ title: loaded.title, description: loaded.description }, loaded),
status: { privacyStatus: 'unlisted' }
});
So a visibility change is really a full update, and Trap 1 applies to it too.
Trap 3: reads lag behind writes
Right after a write, YouTube's own reads can briefly disagree with it. I have seen a playlist I had just created missing from playlists.list for a few moments afterwards.
Two habits keep that from reaching users:
- Don't reload after an edit. The update's response, and the values you just sent, are the truth. Patch them into your own state rather than re-reading a list that may still hold the old title.
-
Don't treat "missing from the list" as "deleted". If a playlist you expect isn't in
playlists.list, ask for it by id (playlists.list?id=...) before telling the user it is gone.
Or skip the code
If you just want to edit your own playlists, that's what TidyList's playlist editor does: a playlist's title, description and visibility, and its videos in bulk, picked by YouTube category or title and removed, copied or moved in one step. Opening playlists and drafting changes are free. Saving them to YouTube needs TidyList Pro (£4.99, one-off), and nothing changes until you confirm.
Questions about the API side are welcome in the comments.
Top comments (0)