Error Metafield, Required parameter is missing or Invalid

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](mailto: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

Solved by adding headers

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

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',
    },
  },
);

@PublicApps thank you very much for the answer it really helped!

@PublicApps I was too early celebrating. Get method working fine, Tested post method with postman.com works fine too, but when try make call in app getting error “metafield: “Required parameter missing or invalid”” json valid(values same as in postman and worked). Stuck and can’t find any solution.

This is my pages/blog.js

fetch(
      "/api/blogs/" + blog.blog_id + "/articles/" + blog.id + "/metafields",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          metafield: {
            namespace: "repasnepapas",
            key: "warehouse123",
            value: "belekas123",
            value_type: "string",
          },
        }),
      }

my server.js

router.post(
    "/api/blogs/:blogId/articles/:articleId/metafields",
    async (ctx) => {
      const { shop, accessToken } = ctx.session;
      try {
        const results = await fetch(
          "https://" +
            shop +
            "/admin/api/2021-01/blogs/" +
            ctx.params.blogId +
            "/articles/" +
            ctx.params.articleId +
            "/metafields.json",
          {
            method: "POST",
            headers: {
              "X-Shopify-Access-Token": accessToken,
              "Content-Type": "application/json",
            },
          }
        )
          .then((response) => response.json())
          .then((json) => {
            return json;
          });
        ctx.body = {
          status: "success",
          data: results,
        };
      } catch (err) {
        console.log(err);
      }
    }
  );

Thank you for any help.

I seems to me that you are POSTing metafield data to our own backend, but your backend is not POSTing it to Shopify