If you know the collection you wish to dupe, and the collection you wish to parent to, consider something like below. Because a collection can have many parents, I'm not totally sure without using the outliner how to determine which instance of the collection is being duped, and hence where in the hierarchy to paste.
As a test, I've copied the context collection to to the scene collection, with and without linked data. Using a method that recursively creates a new collection and populates it with object copies from the source.
def copy_objects(from_col, to_col, linked):
for o in from_col.objects:
dupe = o.copy()
if not linked and o.data:
dupe.data = dupe.data.copy()
def copy(parent, collection, linked=False):
cc = bpy.data.collections.new(collection.name)
copy_objects(collection, cc, linked)
for c in collection.children:
copy(cc, c, linked)
# test script
context = bpy.context
scene = context.scene
col = context.collection
assert(col is not scene.collection)
parent_col = context.scene.collection
# and linked copy
copy(scene.collection, col, linked=True)
For a totally linked copy, ie the objects and collections within are linked copies then
cc = collection.copy()
will do the trick.
Change active collection