Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: API call to set manual product sort order within a collection?

API call to set manual product sort order within a collection?

Denizthemenace
Shopify Partner
29 2 10

Hi,

can I set the manual sort order within a collection programmatically?

Thanks

Zin

Replies 4 (4)

csam
Shopify Staff (Retired)
267 40 51

Hi @Denizthemenace 

You can add products to a manual collection via the API and specify the sort order with the position and sort_value fields. You should be able to have an app programatically add the products to a collection as long as you have them listed in the desired order on your end.

Here's a link to the relevant documentation - Collect is the endpoint that adds products to collections - https://shopify.dev/api/admin/rest/reference/products/collect

To learn more visit the Shopify Help Center or the Community Blog.

cgregnanin
Shopify Partner
26 0 6

Hi, can you provide me some examples?

I am trying but doesn't work

 

curl -d '{"collect":{"product_id":5015268524165,"collection_id":263249199237,"sort_value":"14"}}' -X POST "https://my-shop.myshopify.com/admin/api/2021-10/collects.json" -H "X-Shopify-Access-Token: shppa_380de19cc965XXXXXXaba" -H "Content-Type: application/json"

{"collect":{"id":28940172394629,"collection_id":263249199237,"product_id":5015268524165,"created_at":"2021-12-29T21:20:51+01:00","updated_at":"2021-12-29T21:20:51+01:00","position":7,"sort_value":"0000000007"}}%

Koray
Shopify Partner
8 0 11

Did you ever figure this out?  This does not work on my end either,

jacksos101
Shopify Partner
5 0 6

There seems to be two API endpoints that are made to reorder collections.

 

REST Api - Updates the ordering type of products in a smart collection

and 

GraphQL - collectionReorderProducts 

 

The REST endpoint seems to be broken when it comes to reordering products - don't waste your time with it. Ask it to move 20 products to the top of the collection, and you're lucky if it moves anything.

 

I'm testing the GraphQL endpoint now - hopefully it will work.

 

Something has to work, because the app 'Power Tools Suite' is able to shuffle collections randomly, and I think the above endpoints are the only ways that they could achieve this.