I am able to create a product/variant with metafields in the GraphQl Playground:
===============================================================
mutation CreateShopifyVirtualProduct($productInput: ProductInput!) {
productCreate(input: $productInput) {
product {
id
}
userErrors {
field
message
}
}
}
=== Query Variables ===========
{
“productInput”:
{
“title”: “NIKE - 449788022”,
“descriptionHtml”: “MEN’S SHOES 42-MENS L/S TEES”,
“productType”: “”,
“vendor”: “NIKE”,
“options”: [“size”, “width”],
“metafields”: [
{
“namespace”: “smp_product_attr”,
“key”: “smp_product_key_1”,
“value”: “smp_product_key_1_value”,
“type”: “single_line_text_field”
}
],
“variants”: [
{
“price”: “39.99”,
“sku”: “38536314-0acb-4d3f-b8ff-a0f2014d2c75”,
“weight”: 1,
“weightUnit”: “OUNCES”,
“options”: [“42”, “L/S”],
“metafields”: [
{
“namespace”: “smp_variant_attr”,
“key”: “smp_variant_key_1”,
“value”: “smp_variant_key_1_value”,
“type”: “single_line_text_field”
},
{
“namespace”: “smp_variant_attr”,
“key”: “smp_variant_key_2”,
“value”: “smp_variant_key_2_value”,
“type”: “single_line_text_field”
}
]
}
]
}
}
When I try to duplicate this action in my code, I receive the following Graphql error:
Error: GraphQL error: Variable $productInput of type ProductInput! was provided invalid value for metafields.0.type (Field is not defined on MetafieldInput), variants.0.metafields.0.type (Field is not defined on MetafieldInput), variants.0.metafields.1.type (Field is not defined on MetafieldInput)
I believe I am pointing to the correct endpoint ==>
My getSubscriptionUrl.js file:
const response = await fetch(https://${shop}/admin/api/2021-07/graphql.json, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
“X-Shopify-Access-Token”: accessToken,
},
body: query
})
I can create products in my code if I remove the metafield object. It feels as though I am reaching an older version of the Graphql server. Any thoughts of what I may be doing wrong? Thanks, Tom