Error Metafield, Required parameter is missing or Invalid

Andrew_Sutanto
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
Andrew_Sutanto
Tourist
13 0 1

Solved by adding headers

0 Likes
I_KNOW_NOTHING
Excursionist
31 0 6

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

0 Likes
PublicApps
Shopify Partner
85 4 23

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.
- If my reply was helpful, please Like it or mark it as Accepted Solution to let me know!
- Need store customizations? Then consider Hiring us.
Darius90
Tourist
6 0 2

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

0 Likes
Darius90
Tourist
6 0 2

@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.

0 Likes
PublicApps
Shopify Partner
85 4 23

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

Just trying to help out.
- If my reply was helpful, please Like it or mark it as Accepted Solution to let me know!
- Need store customizations? Then consider Hiring us.
0 Likes