Loading...

How to filter product by their name and customer id in Graphql ?

Pravin Prajapati  ·   21 Dec 2022
How to filter product by their name and customer id in Graphql ?
service-banner

Introduction

GraphQL is a strong programming language that allows developers to design efficient and flexible APIs. When it comes to filtering data, GraphQL provides various options, including the customer ID filter, which allows users to search for specific products by their name and customer ID. In this blog post, we'll explore how to implement this feature and discuss the benefits of using GraphQL for filtering data. So, let's get started!

To filter products by name and customer ID, we can use the following GraphQL query:

Coding : step-by-step with description

js

query products($filter: ProductAttributeFilterInput){
 products(filter: $filter) {
   items {
     name
     sku
     url_key
     stock_status
     price_range {
       minimum_price {
         regular_price {
           value
           currency
         }
       }
     }
   }
   total_count
   page_info {
     page_size
   }
 }
}

Below code we have pass at QUERY VARIABLES

{
 "filter":{
   "sku":{
     "in":["Jagat Devsutra HERBAL Activated Charcoal Toothpaste",
   "Jagat Devsutra HERBAL Fresh Mint Flavour Toothpaste -100g",
   "EcoSattva 3R – Natural Bath & Body Wash 200ml"]
   },
   "customer_group_id":{
     "eq":1
   }
 }
}

  • Also we have ass authorization token:

{ "authorization": "Bearer yourToken" }