Solved

Remove all products from a custom collection with REST admin api

taylan1
Shopify Partner
2 0 0

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?

 

 

Accepted Solution (1)

Liam
Shopify Staff
2731 302 778

This is an accepted solution.

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?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

Liam
Shopify Staff
2731 302 778

This is an accepted solution.

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?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

taylan1
Shopify Partner
2 0 0

Yes that solved my problem, thanks!

kristinam
Shopify Partner
5 0 0

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