Create version and put it in a Playlist

Hi,
I’m currently using the API to create a version, now I need to put that version into a playlist or create a new playlist. How can i get a list of the existing playlists? I don’t see much in the api docs.

You may find going through this exercise helpful:

https://developers.shotgridsoftware.com/python-api/cookbook/tutorials.html#basic

But in general, you can do this:

Find existing playlists for the current project
Assuming 200 is the project id.

from pprint import pprint

playlists = sg.find("Playlist", filters=[["project.Project.id", "is", 200]], fields=["code"])

pprint(playlists)

This should print a list of playlist entities (dictionaries).
The Sg api will always return the type and id even if you didnt ask for those fields.

You need the type and id as minimum to update a field with an entity connection (single or multi entity fields).

Update the Version to add it to the Playlist
Assuming version is your version dictionary you just created

update_data = {
    "playlists": [version]
}
sg.update("Version", version.get("id"), update_data)

You can also update the Playlist instead and add the version to its list of versions (field).

In both cases you may need to use multi_entity_update_modes to ensure you don’t overwrite the playlists field with just the version. You likely want to add it.

update_data = {
    "playlists": [version]
}
sg.update("Version", version.get("id"), update_data, multi_entity_update_modes={"playlists": "add"})
2 Likes