Get variant by id with admin graphQL

mRichman
Visitor
2 0 0

Hi,

I'm trying to get a variant by ID using the graphQL, I need to use the graphQL as the fields I need aren't available in the rest api. Having looked around what I'm doing should be correct, it's the accepted answer on a few posts from 2019/2020. However I'm facing the error: "Field 'productVariants' doesn't accept argument 'id'". The same call works fine for products if I switch out the top line to "product(id: "gid://shopify/Product/6728415838363") {"

My graphQL:

{
  productVariants(id:"gid://shopify/ProductVariant/39865779749019") {
    id
    storefrontId
}
}
Copy

 

 

full error:

{
    "errors": [
        {
            "message": "Field 'productVariants' doesn't accept argument 'id'",
            "locations": [
                {
                    "line": 2,
                    "column": 19
                }
            ],
            "path": [
                "query",
                "productVariants",
                "id"
            ],
            "extensions": {
                "code": "argumentNotAccepted",
                "name": "productVariants",
                "typeName": "Field",
                "argumentName": "id"
            }
        },
        {
            "message": "Field 'id' doesn't exist on type 'ProductVariantConnection'",
            "locations": [
                {
                    "line": 3,
                    "column": 5
                }
            ],
            "path": [
                "query",
                "productVariants",
                "id"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "ProductVariantConnection",
                "fieldName": "id"
            }
        },
        {
            "message": "Field 'storefrontId' doesn't exist on type 'ProductVariantConnection'",
            "locations": [
                {
                    "line": 4,
                    "column": 5
                }
            ],
            "path": [
                "query",
                "productVariants",
                "storefrontId"
            ],
            "extensions": {
                "code": "undefinedField",
                "typeName": "ProductVariantConnection",
                "fieldName": "storefrontId"
            }
        }
    ]
}
Copy


If you have any ideas I'd be incredibly grateful. I'm using the 2021-04 api.

Thanks.

Reply 1 (1)

VivekH
Excursionist
12 1 14

Hey @mRichman 

Try with this

{
  productVariant(id:"gid://shopify/ProductVariant/39865779749019") {
    id
    storefrontId
}
}

 you cannot query productVariants with a single id