Create Product with Global Title Tag Metafield using GraphQl

tomasdelaveau
New Member
8 0 0

Hello everyone! I'm trying to create a product with a Global Title Tag Metafield.
Posting the following body creates the product without the metafield:

 

mutation {
      productCreate(input: {
        title: "sync test",
        options:["Option 1"],
        variants: [
          {
            sku: "default",
            price: "0",
            inventoryItem: {
              cost: 0.0,
              tracked: true
            }
          }
        ],
        metafields: [
          {
            namespace: "global",
            key: "title_tag",
            value: "sync test",
            valueType: STRING
          }
        ]
      }) {
    product {
      id
      metafields(first: 10, after: null) {
        edges {
          node {
            key
            namespace
            value
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

Here's the response body:

 

{
  "data": {
    "productCreate": {
      "product": {
        "id": "gid:\/\/shopify\/Product\/6660968186020",
        "metafields": {
          "edges": []
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 22,
      "actualQueryCost": 12,
      "throttleStatus": {
        "maximumAvailable": 1000.0,
        "currentlyAvailable": 988,
        "restoreRate": 50.0
      }
    }
  }
}

 

If I change the metafield value to any string different to the product title, the metafield get's created. For example, the same request with "sync_test" as the value of the metafield works fine. Here's the response (where you can see the metafield was created):

 

{
  "data": {
    "productCreate": {
      "product": {
        "id": "gid:\/\/shopify\/Product\/6660967858340",
        "metafields": {
          "edges": [
            {
              "node": {
                "key": "title_tag",
                "namespace": "global",
                "value": "sync_test"
              }
            }
          ]
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 22,
      "actualQueryCost": 13,
      "throttleStatus": {
        "maximumAvailable": 1000.0,
        "currentlyAvailable": 987,
        "restoreRate": 50.0
      }
    }
  }
}

 

Do you know what's the reason of this behaviour?

0 Likes
_JCC_
Shopify Staff
Shopify Staff
143 20 26

Hey @tomasdelaveau ,

Did some internal investigations and this is expected behaviour. The rationale is to avoid duplicating a product field like title in metafields. Is there a reason why you wanted to have the same info as the product title in a metafield? If you can provide a little more context on what you're trying to accomplish I can certainly share that info internally and potentially create an enhancement request to have this restriction removed. That being said, I wouldn't be able to provide a timeline on the when and if it gets changed.

Regards,
John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes