Admin GraphQL API: how to get the product position in a collection ?

Searchanise_Tea
Tourist
8 0 2

Hello!

Could you please let us know how to get the product position in a collection through the Admin GraphQL API ?

 

0 Likes
Alex
Shopify Staff
Shopify Staff
1555 81 293

The position of products in collections is surfaced via the Collects resource. At this time, Collects are not surfaced via the GraphQL Admin API. For now, you'll have to determine this with REST. With that said, the goal is 100% parity, so it should get there eventually, stay tuned!

Cheers.

Edit

See Dominique's post below!

0 Likes
Dominique_Simo1
Shopify Staff
Shopify Staff
40 0 11

Hi there!

That's actually not quite right. We don't expose the position on GraphQL because position is brittle and its non-performant to keep updated accurately. We do expose products on a collection in correctly sorted order, from which you can easily infer a position if required.

 

I highly recommend you do not use the Collects API to do this, as we are looking to deprecate some aspects of it.

 

Here's an example query:

query test {
  collection(id:"gid://shopify/Collection/60788375608") {
    id
    title
    productsCount
    products(first: 250) {
      edges {
        node {
          id
          title
        }
      }
    }
  }
}
 

Thanks!

Dominique

Thomas_Lang1
Shopify Partner
156 4 31

Is this still not available in graphql?

We use REST to PUT a lot of products to a custom_collection, now we need a way to get all the collects_ids at once

 

0 Likes