Querying Selected Options in Storefront API

Steve_F
Shopify Partner
4 0 1

Hey, Im trying to use the storefront API to pull up a product variant using the variantBySelectedOptions field, but the documentation isn't clear on the type of data it needs.  It says it needs a product option's name and value.  I'm executing this query on a test product in graphiql:

{
  node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzEwMDkxMDg2NTI5") {
    id
    ... on Product {
      title
      id
      handle
      variantBySelectedOptions(selectedOptions:{name:"option1",value:"Large"}){
        id
      }
    }
  }
}

 

I'm assuming here the option name is "option1", but it's unclear what's needed here.  I also don't know what it's expecting for the value.

Currently all combinations of data I'm inputting return a null response.  Can anyone offer some assistance with this?

Replies 3 (3)

Steve_F
Shopify Partner
4 0 1

Well, I figured it out after trying everything.  

 

{
  node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk5NDE4NDg3Njk=") {
    id
    ... on Product {
      title
      id
      handle
      variantBySelectedOptions(selectedOptions: [{name: "Color", value: "Black Sculpturalottoman"},{name: "Size", value: "S"}]){
        id
        
      }
    }
  }
}
 

Please add this to the documentaion. It's way too hard to work with it as it is.

nidhi125
Visitor
2 0 0

It didn't work, and i can't find in any document. I want to querying variant or product By Selected Options in graphql. how is work it?

dev88
Tourist
11 0 6

Need this solution as well..