Hello Team
I Have worked with graphql API for products data
I want to get all product vendor, title, and variant options data with particular tags and types.
For this, I used below code
$query = array(“query” => ’
{
products(first: 250, query: "status:active product_type:‘.$new_product_type_name.’ tag:‘.$new_colour_name.’ " ) {
edges {
node {
variants(first: 1) {
edges {
node {
selectedOptions {
name
value
}
}
}
}
featuredImage {
id
url
}
handle
vendor
title
priceRange {
minVariantPrice {
amount
}
}
}
}
}
}
');
It’s not working
Could you please guide me?
okur90
March 31, 2023, 3:10pm
2
Hi @Surbhi106
I observed a minor problem in your GraphQL query. The problem lies in the query parameter string within the products field. You need to wrap the values for product_type and tag in double quotes, while using single quotes for the entire string.
$query = array("query" => '
{
products(first: 250, query: "status:active product_type:\"'.$new_product_type_name.'\" tag:\"'.$new_colour_name.'\"" ) {
edges {
node {
variants(first: 1) {
edges {
node {
selectedOptions {
name
value
}
}
}
}
featuredImage {
id
url
}
handle
vendor
title
priceRange {
minVariantPrice {
amount
}
}
}
}
}
}
');
okur90
April 1, 2023, 1:36pm
3
$query = array("query" => '
{
products(first: 250, query: "status:active product_type:\"' . $new_product_type_name . '\" tag:\"' . $new_colour_name . '\"") {
edges {
node {
variants(first: 1) {
edges {
node {
selectedOptions {
name
value
}
}
}
}
featuredImage {
id
url
}
handle
vendor
title
priceRange {
minVariantPrice {
amount
}
}
}
}
}
}
');
Hello Okur90,
Thank you for the suggestion!
But I am not facing an issue with the product query code mentioned below,
{ products(first: 250, query: “status:active product_type:"’ . $new_product_type_name . ‘" tag:"’ . $new_colour_name . '"”)
When I use below code, it’s working fine
$query = array(“query” => ’
{
products(first: 250, query: "status:active product_type:‘.$new_product_type_name.’ tag:‘.$new_colour_name.’ " ) {
edges {
node {
id
featuredImage {
id
url
}
handle
vendor
title
priceRange {
minVariantPrice {
amount
}
}
}
}
}
}
');
But when I try to get the product option name and value or use below code
$query = array(“query” => ’
{
products(first: 250, query: "status:active product_type:‘.$new_product_type_name.’ tag:‘.$new_colour_name.’ " ) {
edges {
node {
variants(first: 1) {
edges {
node {
selectedOptions {
name
value
}
}
}
}
featuredImage {
id
url
}
handle
vendor
title
priceRange {
minVariantPrice {
amount
}
}
}
}
}
}
');
It’s the result I find null data.
Could you please guide me on how can I get product options’ name and values using
products(first: 250, query: "status:active product_type:‘.$new_product_type_name.’ tag:‘.$new_colour_name.’ " )
This query?
Thank you