How to add definition on existing metafields without definition using Shopify APIs

I am looking for Shopify API (Admin Rest or GraphQL APIs) through which we can add metafield definition for existing metafields available in store without definition. I am looking this for order and customer metafields.
Also, here I wanted to use same key and namespace associated with existing metafields without definition.

This can can be possible through UI (from Shopify store admin as shown in ) but I am not able to find way to do it programmatically using APIs. Hence looking for help here.

1 Like

That is my concern as well.

When I press “Add definition” Shopify seems to be sending the following request.

{"operationName":"MetafieldDefinitionMigrateMutation","variables":{"input":{"visibleToStorefrontApi":true,"useAsCollectionCondition":false,"pin":true,"namespace":"omni_hub","key":"customer_code","type":"single_line_text_field","validations":[],"name":"会員コード","description":"","ownerType":"CUSTOMER","forceCreate":true}},"query":"mutation MetafieldDefinitionMigrateMutation($input: MetafieldDefinitionInput!) {\n  metafieldDefinitionCreate(definition: $input) {\n    createdDefinition {\n      id\n      __typename\n    }\n    userErrors {\n      code\n      message\n      field\n      __typename\n    }\n    validationJob {\n      id\n      __typename\n    }\n    __typename\n  }\n}\n"}

This looks exactly like the metafieldDefinitionCreate mutation in the Admin API (GraphQL), except for the unfamiliar parameter forceCreate.

Is this the interface that only Shopify can use?

I would love to see forceCreate made available to the Admin API as well!

1 Like