Shopify: Unable to create Product options using GraphQL API

Hi Shopify experts,

I’m trying to create options and variants for product using GraphQL API.

Always I’m getting

LINKED_METAFIELD_DEFINITION_NOT_FOUND

error.

Creating Products:

While Creating the product, I’m sending following info in variables:

“metafields”=> [
[
“namespace”=> “products-meta”,
“key”=> “product-title”,
“type”=> “single_line_text_field”,
],
[
“namespace”=> “products-meta”,
“key”=> “product-finish”,
“type”=> “single_line_text_field”,
],
[
“namespace”=> “products-meta”,
“key”=> “product-shade”,
“type”=> “single_line_text_field”,
],
]

Creating Options:
And while creating the options:

$variables = [
“productId” => $product->shopifyproductid,
“options” => [
[
“name”=>“Finish”,
“linkedMetafield”=>[
“namespace”=>“products-meta”,
“key”=>“product-finish”,
‘values’=>[‘Brushed Nickel’, ‘Olde Bronze’, ]
],
],
],
];

While creating the options, I’m getting LINKED_METAFIELD_DEFINITION_NOT_FOUND error.
Not sure whats wrong I’m doing here. Your help will be appreciated.

Thanks,
Jay

Hi there

Before creating your product with product options, have you checked the definitions of your metafields by using GraphQL queries to determine if they exist?

query {
  metafieldDefinitions(first: 250, ownerType: PRODUCT) {
    edges {
      node {
        name
        namespace
        key
        type {
          name
        }
      }
    }
  }
}
1 Like