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

Replies 6 (6)

Andrew_Sutanto
Tourist
13 0 1

Solved by adding headers

I_KNOW_NOTHING
Shopify Partner
45 0 11

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

PublicApps
Shopify Partner
146 5 34

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

 

 

 

Public Apps | Theme customization & App development
 - Was my reply useful? Like it to let me know!
 - Did I answer your question? Please mark as Accepted Solution.
 - Need more help? Contact us.

Darius90
Shopify Partner
34 0 9

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

...
Darius90
Shopify Partner
34 0 9

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

...
PublicApps
Shopify Partner
146 5 34

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

Public Apps | Theme customization & App development
 - Was my reply useful? Like it to let me know!
 - Did I answer your question? Please mark as Accepted Solution.
 - Need more help? Contact us.