Hello,
I need to get randomly one buyable productVariant id for my preview feature via GraphQL API so that I can redirect the customer directly to the cart with an auto-added product (/cart/add?id=variant_id), but unfortunately, I am not able to get the correct query. It seems that more than one query parameter will be not accepted. I tried AND or just whitespace without success.
query {
productVariants(first: 1, query: "published_status:published AND available_for_sale:true") {
edges {
node {
id
availableForSale
}
}
}
}
query {
products(first: 1, query: "published_status:published available_for_sale:true") {
edges {
node {
variants(first: 1) {
edges {
node {
id
availableForSale
}
}
}
}
}
}
}
In general, I need a query to get a productVariantId where the product is published and variant is buyable (“quantity” > 0 and track “track quantity” equals true or “Continue selling when out of stock” equals true or “track quantity” equals false).
Any idea? Thanks for your help!
Best,
Dennis
