Remove all products from a custom collection with REST admin api

I need a structure on custom collections which allows me to change the products of the collection using the product_type, so when the product type changes, ALL the products of the collection needs to be changed. I figured i can add multiple products using the /custom_collections PUT endpoint like the following:

{
    "custom_collection": {
        "collects": [
            {
                "product_id": 1234
            },
            {
                "product_id": 1235
            }
        ]
    }
}

but that only adds products to the collection, doesn’t remove them, so if i use it like this:

{
    "custom_collection": {
        "collects": []
    }
}

it doesnt remove the old products. how can i remove/change all the products at once? is it possible?

Hi Taylan,

It’s possible that it might be easier to use the collectionRemoveProducts mutation, which is part of the GraphQL API - however you’ll still need to provide product IDs. Would this work for you?

1 Like

Yes that solved my problem, thanks!

Hi @Liam does this work for manual collections only? Then how to remove products from automatic collections? Thanks!