Problem with sort key PRICE

Topic summary

A developer encountered an error when trying to use sortKey=PRICE in a Shopify Storefront API query for products in a post-checkout extension. The API returned an invalid value error, stating it expected type ‘ProductSortKeys’.

Initial Suggestion:

  • Change sortKey to ProductSortKey (though this appears to be a misunderstanding)
  • Test queries using Shopify’s GraphiQL explorer

Working Solution Provided:
The helper shared a corrected GraphQL query that successfully includes sortKey: PRICE in the products query. Key changes in the example:

  • Proper syntax: sortKey: PRICE within the products query parameters
  • Updated field names (e.g., priceRange instead of priceRangeV2, priceV2 for variants)
  • quantityAvailable instead of inventoryQuantity

Recommendation:
Use Shopify’s GraphiQL Storefront explorer to build and test queries interactively with sample data before implementing in code.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

Hi, I saw the documentation and according to it it is possible to pass a parameter sortKey= PRICE, but it gives me the error pasted below, for him this parameter does not exist can you help me?

I call the function in a route, to get the products and use them in the extension

https://shopify.dev/docs/api/storefront/latest/queries/products?language=Node.js

{
18:55:26 │ remix      │   errors: [
18:55:26 │ remix      │     {
18:55:26 │ remix      │       message: "Argument 'sortKey' on Field 'products' has an invalid value (PRICE). Expected type 'ProductSortKeys'.",
18:55:26 │ remix      │       locations: [Array],
18:55:26 │ remix      │       path: [Array],
18:55:26 │ remix      │       extensions: [Object]
18:55:26 │ remix      │     }
18:55:26 │ remix      │   ]
18:55:26 │ remix      │ }
1 Like

change sortKey to ProductSortKey.
u can check your query at https://shopify.dev/graphiql/storefront-graphiql

I’m using the request in a post checkout extension.

This is my code:

let query = `query GetLeastExpensiveProducts {
    products(first: 20, reverse: false) {
    edges {
      node {
        id
        title
        media(first:1){
          edges{
            node{
              ...on MediaImage{
                image{
                  url
                }
              }
            }
          }
        }
        priceRangeV2{
          minVariantPrice{
            amount
          }
        }
        variants(first: 10) {
          edges {
            node {
              id
              title
              price
              inventoryQuantity
              displayName
              compareAtPrice
            }
          }
        }
      }
    }
    }
      }`;

try this:

query GetLeastExpensiveProducts {
  products(first: 20, reverse: false, sortKey: PRICE) {
    edges {
      node {
        id
        title
        media(first: 1) {
          edges {
            node {
              ... on MediaImage {
                image {
                  url
                }
              }
            }
          }
        }
        priceRange {
          minVariantPrice {
            amount
          }
        }
        variants(first: 10) {
          edges {
            node {
              id
              title
              priceV2 {
                amount
              }
              quantityAvailable
              compareAtPriceV2 {
                amount
              }
            }
          }
        }
      }
    }
  }
}

i used pricerange instead of pricerangev2, only to test it in graphql explorer
u realy should test the graphql explorer:
https://shopify.dev/graphiql/storefront-graphiql
click on explorer and u can build the request u need. u may even test the request on sample data