Need a way of getting multiple products by id using filter query

Topic summary

Problem: A developer needed to retrieve multiple Shopify products by ID using GraphQL’s filter query. Their initial attempt using full GID format in OR conditions failed, though title-based filtering worked.

Solutions provided:

  • Use numeric IDs only: Strip the gid://shopify/Product/ prefix and query with just the numeric portion: query: "(id:8042415816983) OR (id:8105484845335)"

  • Use the nodes query (recommended): A more elegant approach that accepts full GIDs as variables:

query Products($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Product { id, title }
  }
}

This pattern also works for other Shopify objects like OnlineStorePage with metafields.

Recent development: One user reported the solution stopped working after a recent date, suggesting possible API changes. The thread remains open with this unresolved issue.

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

I am trying to get multiple products via their id using graphql Api.

My query is :

query MyQuery {
  products(first: 20, query: "(id: gid://shopify/Product/8042415816983) OR (id: gid://shopify/Product/8105484845335)") {
    edges {
      node {
        title
        id
      }
    }
  }
}

For example I need 5 products detail . I have their ids so I will use OR in filter.
By this way I am not getting those products.
Though By title search the filtering is working fine.

"(title: A title) OR (title: Demo product)"

Is there any way I can achieve this ?

product query id filter is just the numeric part of the id, not the whote gid://

Do this (verbatim, i.e. whitespace in the quoted query is significant):

query MyQuery {
  products(first: 20, query: "(id:8042415816983) OR (id:8105484845335)") {
    edges {
      node {
        title
        id
      }
    }
  }
}
3 Likes

Another possible solution.

query Products($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on Product {
      id
      title
      images (first: 1){
        nodes {
          url(transform: {maxHeight: 80, maxWidth: 80})
        }
      }
    }
  }
}

variables: {"ids": ["gid://shopify/Product/8153588367651", "gid://shopify/Product/8153588465955", "gid://shopify/Product/8153588793635", "gid://shopify/Product/8153588695331", "gid://shopify/Product/8153589023011"]}
3 Likes

@Stephen2020 - Very elegant solution. Thank you so much. Never thought of using the Node interface this way. Opens up a lot of possibilities. (Ex: querying metafields on an online store’s page. Currently, there is no way to get this via GraphQL API).

1 Like

Thank you for your kind words. Not sure whether I’ve understood you correctly about querying metafields on an online store’s page.

If you know the page id(s) then you can try it like that.

query Pages($ids: [ID!]!) {
  nodes(ids: $ids) {
    ... on OnlineStorePage {
      id
      metafields(first: 10) {
        nodes {
          key
          namespace
          value
        }
      }
    }
  }
}

variables: {"ids": ["gid://shopify/OnlineStorePage/143740731675"]}

This used to work anymore, but not anymore after yesterday. Any idea what has happened?

1 Like

(posting that didn’t work and that I can’t delete)