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.

Re: Create metadata field for an existing product graphql

Solved

Create metadata field for an existing product graphql

jason90
Shopify Partner
15 2 2

I have a mutation query I am working on for to create or update a metadata field into an already existing product. Here is the structure of the query:

 

mutation {Product1: productUpdate(
    input: {
        id: "existing product id",
        metafields: {
id: "existing metafield id" namespace: "some namespace", key:"some key", value:"some value" } }) { product { id title metafields(first: 10) { edges { node { id key value namespace } } } } } }

 

The query works if the metadata id already exists, however it doesn't create a new metadata field if I remove the id key from the metadata portion of the query (the response returns no metadata fields). The productCreate mutation doesn't seem to accomplish what I want either.

 

If we aren't able to create new metadata fields in this way, how can go about doing that?

 

Accepted Solution (1)

jason90
Shopify Partner
15 2 2

This is an accepted solution.

I managed to resolve my own issue: turns out all I needed to do was include the valueType key in the metadata parameters and its working fine.

View solution in original post

Replies 2 (2)

jason90
Shopify Partner
15 2 2

For some additional context, I have a request id done using my test store: 8628ca25-6209-4420-abde-75fb372b925b. I am using the api version 2020-01.

jason90
Shopify Partner
15 2 2

This is an accepted solution.

I managed to resolve my own issue: turns out all I needed to do was include the valueType key in the metadata parameters and its working fine.