Shopify API call to get variant of a product graphQL

Hello I have the following cURL:

curl -X POST
https://your-development-store.myshopify.com/admin/api/2022-10/graphql.json
-H ‘Content-Type: application/json’
-H ‘X-Shopify-Access-Token: {access_token}’ \s

  • d

'{
“query”: “query { productVariants(query : “(title:S) AND (product_id:7253232058557”) { edges { node { id title inventoryQuantity} } } }”

}’
}

I am trying to get the variant title S of a specific product (Black Hoodie with ID :7253232058557) but it returns the error 400 saying “Bad Request”. What am I doing wrong?

1 Like

Hi @HiT2 :waving_hand:

A few things to note here:

So the query would look something like the below:

query FilteredVariants($search: String!){
    productVariants(first:5, query: $search){
        nodes {
            title
            inventoryQuantity
        }
    }
}

{ // variables
    "search": "title:S AND product_id:7253232058557"
}

That would make the cURL request:

curl -X POST \
'https://{{SHOP}}.myshopify.com/admin/api/2022-10/graphql.json' \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {{TOKEN}}' \
-d '{"query":"query FilteredVariants($search: String!){ productVariants(first:5, query: $search){ nodes { title inventoryQuantity } }}","variables":{"search":"title:S AND product_id:7253232058557"}}'

Hope that helps!

Thank you!
I was also wondenring, is it possible to change the variant of a product of an order through PUT API call?

Thank you!
I was also wondenring, is it possible to change the variant of a product of an order through PUT API call?