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.
@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).