Can't add Metafield to a product

Nelson_Taveras
Visitor
2 0 0

Hello,

I'm trying to add a metafield to one of the products of my store. I'm currently using the sample data provided in the Metafield API documentation:

{
  "metafield": {
    "namespace": "inventory",
    "key": "warehouse",
    "value": 25,
    "value_type": "integer"
  }
}

And the URL i'm sending my POST request to: 

/admin/products/#{id}/metafields.json

However I keep getting the following error every time:

{ error: { product: 'Required parameter missing or invalid' },
  code: 400 }

Any suggestions/ideas on how to fix this?

Thanks in advance.

Replies 5 (5)

HunkyBill
Shopify Expert
4851 60 559

Did you try changing the #{id} to be the ID of an actual existing product in your POST? 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com

Nelson_Taveras
Visitor
2 0 0

Yes I did, I intentionally left the placeholder in my original post.

nvwoods
Visitor
2 0 0

I'm coming up against the exact same issue.

Accessing existing metafields is fine, I can do that no problem, but if I try to add or edit and existing metafield then I get the same 'required parameter missing or invalid' error.

I've tried numerous ways and no luck.

Examples (I've fudged the URL so as not to reveal client data):

URL: https://example.myshopify.com/admin/products/2003472641/metafields/9015105921.json

Method: PUT

Payload: {"metafield": {"id": 9015105921, "value": "test", "value_type": "string" }}

I'm pretty sure it's either not working as it should or the documentation is out of date or incorrect.

 

 

nvwoods
Visitor
2 0 0

I'm coming up against the exact same issue.

Accessing existing metafields is fine, I can do that no problem, but if I try to add or edit and existing metafield then I get the same 'required parameter missing or invalid' error.

I've tried numerous ways and no luck.

Examples (I've fudged the URL so as not to reveal client data):

URL: https://example.myshopify.com/admin/products/2003472641/metafields/9015105921.json

Method: PUT

Payload: {"metafield": {"id": 9015105921, "value": "test", "value_type": "string" }}

I'm pretty sure it's either not working as it should or the documentation is out of date or incorrect.

 

 

Matthew_Moorhou
Visitor
2 0 2

Hey there, we had exactly the same thing. Turned out that you have to explicitly tell Shopify that you’re sending it up as a JSON object.

Not quite sure on the technicals of that, but I know that's what we had to do. If that still leaves you without the solution let me know and I will see if I can find out more.

Good luck with it! Matt