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

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)