Error Metafield, Required parameter is missing or Invalid

Highlighted
Tourist
13 0 1

So currently i am testin on my csv plugin and after i upload it keeps returning

{"errors":{"metafield":"Required parameter missing or invalid"}}

although I have send the link to 

token@website.com/admin/products/id/metafields.json

and my Json was

{"metafield":{"namespace":"productfield","key":"author","value":"Daniel Levitin","value_type":"string"}}

Why does i kept receiving this error? and how do i fix it thank you

0 Likes
Highlighted
Tourist
13 0 1

Solved by adding headers

0 Likes
Highlighted
Excursionist
31 0 5

Care to explain how did you manage to make this work?

0 Likes
Highlighted
Shopify Partner
43 1 9

When the endpoint returns 

{"errors":{"metafield":"Required parameter missing or invalid"}}

Make sure you are sending valid JSON in your request body and the data contains all required parameters (so an object with a single key called 'metafield', and within that the keys 'key', 'namespace', 'value', and 'value_type'). Also add the Content-Type header to tell the receiver you are sending a JSON string.

E.g.

 

fetch(
  'https://myshop.myshopify.com/admin/api/2020-07/metafields.json',
  {
    body: JSON.stringify({
      metafield: {
        namespace: 'myAppName',
        key: 'myMetafieldKey',
        value: '{"someDataKey":"someDataValue"}',
        value_type: 'json_string',
      },
    }),
    method: 'POST',
    headers: {
      'X-Shopify-Access-Token': 'XXXXXXXXXXX',
      'Content-Type': 'application/json',
    },
  },
);

 

 

 

Just trying to help out.

We are web app developers, SEO ethousiasts, and do all kinds of other cool internet things.
Check us out at https://public-apps.com
0 Likes