How do I set Playlist Sort Order via the API?

I would like to use the API to set the Sort Order of a Playlist I created - how do I do that? I can’t find the field.

2 Likes

If you would like to set the sort order of a Playlist via the API, you will need to access the PlaylistVersionConnection, which is where the sg_sort_order field lives.

Check out the Connection Entities documentation which gives an example of how to access the connection fields.

Without getting into the specifics of the code, here is a way you can set the Sort Order on the connection entities:

  • Create your Versions and make sure you save the outputs of the sg.create() call in a list.
  • Fetch all the connection entities that point to the Playlist you were just attaching Versions to.
  • Edit the Sort Order field on the connection entities based on the Versions you just created.

All in all, this could be optimized down to 3 API calls:

  • One .batch() call to create your Versions
  • One .find() call to get your connection entities
  • One .batch() call to update your sort orders
6 Likes