Duplicate a Collection

Any chance there's a hidden API to duplicate a collection to create a new one? I have a rather large collection that I want to duplicate and the make a few changes to in order to assign it to a subset of clients.

This PowerShell command will fetch all of your collections.

Invoke-WebRequest -Method Get -Uri 'http://localhost:8089/dvr/collections/channels'

This will create a new collection.

$body = '{
    "items": [ "2.1", "4.1", "5.1", "7.1", "9.1", "11.1", "13.1", "28.1", "50.1" ],
    "name": "Test Collection"

Invoke-WebRequest -Method Post -Uri 'http://localhost:8089/dvr/collections/channels/new' -Body $body

In both commands you would substitute your server name or IP address for "localhost".

I'll leave it as an exercise to the reader on how to glue this together to duplicate a collection.


$c = Invoke-WebRequest -Method Get -Uri 'http://localhost:8089/dvr/collections/channels'
$j = ConvertFrom-Json $c.Content
$x = $j | ? { $_.name -eq 'Basic' }
$y = [ordered]@{ items = $x.items; name = 'New Name' }
$b = ConvertTo-Json $y
Invoke-WebRequest -Method post -Uri 'http://localhost:8089/dvr/collections/channels/new' -Body $b

Thank you! It took a little bit to convert this to a curl command but that was still easier than building the copies from scratch.

For those interested:

To retrieve the current collections:

curl -XGET -o /tmp/collections

To post the new collection:

curl -XPOST -H "Content-Type: text/json" --data '{"items":["11.1","17.1","5.1","22.1","fnc","history","motortrend","28.1"],"name":"Favorites1"}'

TIP: Add the new collections (if more than one) one at a time.


It's probably best to just omit the content type header, but if you're going to include it, the proper type for JSON is application/json.

And since GET is the default request type, the -XGET option can be omitted in the first example.