Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

New metafields.type Property

Solved

New metafields.type Property

tomadelaney
Shopify Partner
18 2 2

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

Accepted Solutions (2)
tomadelaney
Shopify Partner
18 2 2

This is an accepted solution.

Thank you -- a version mismatch FEELS like the root cause of my problem.
I will use your valuable "2020-07" information and scour my code.
Thanks again; I will close this one out.
Regards,
Tom

View solution in original post

tomadelaney
Shopify Partner
18 2 2

This is an accepted solution.

Note:

Solved.

Though my SubscriptionURL had been updated to "2021-10",

I missed a separate Graphql Proxy.  It had a value of "July20" & not (2020-07), thus I had difficulty locating it.

I updated the @Shopify/koa-shopify-graphql-proxy": "^6.0.1",  from the earlier "4.1.0",

then changed the version:

server.use(graphQLProxy({ version: "2021-01" }));

... and all was resolved.  Thanks for your help !

View solution in original post

Replies 5 (5)

swalkinshaw
Shopify Staff
20 4 12

My first guess was going to be an API version mismatch. The type field was only added in 2021-07, and GraphQL Playground likely defaults to the latest stable API version so it would work there.

However, your example code did show you using https://${shop}/admin/api/2021-07/graphql.json which is correct. I looked in our logs for requests matching yours and saw a few failing ones where you used version 2020-07 (2020, not 2021) which would explain the failures. However, I also saw successful requests made once you switched to 2021-07 so it looks like you figured this problem out?

To learn more visit the Shopify Help Center or the Community Blog.

tomadelaney
Shopify Partner
18 2 2
swalkinshaw - thanks for your reply.

Unfortunately, I am still stuck.
What you saw in the logs is that I performed many tests using 2021-04,
2021-07, and even the unreleased 2021-10 endpoints .
I did see your change from valueType to type in 2021-07.

Unfortunately, in using either 2021-07 and 2021-10, my product and variant
are only created if I eliminate the metafield objects.
Thanks for your help, again. If you are truly stumped at your end, please
let me know and I will close out this ticket.
swalkinshaw
Shopify Staff
20 4 12

Oh sorry, the successful requests I was seeing were from the Shopify GraphiQL App.

However, every single request I'm seeing from your own app has `2020-07` as the version in the URL. There must be some disconnect between the code snippet you posted here and the actual code used to make the request. I'm sorry I can't really offer more help, but `type` will definitely work if you're using version 2021-07 and newer.

To learn more visit the Shopify Help Center or the Community Blog.

tomadelaney
Shopify Partner
18 2 2

This is an accepted solution.

Thank you -- a version mismatch FEELS like the root cause of my problem.
I will use your valuable "2020-07" information and scour my code.
Thanks again; I will close this one out.
Regards,
Tom

tomadelaney
Shopify Partner
18 2 2

This is an accepted solution.

Note:

Solved.

Though my SubscriptionURL had been updated to "2021-10",

I missed a separate Graphql Proxy.  It had a value of "July20" & not (2020-07), thus I had difficulty locating it.

I updated the @Shopify/koa-shopify-graphql-proxy": "^6.0.1",  from the earlier "4.1.0",

then changed the version:

server.use(graphQLProxy({ version: "2021-01" }));

... and all was resolved.  Thanks for your help !