Want to Update MetaFields on Customer through API

Hi

I am using the flow , First i created the customer then after Make a metafields on that customer but Now my requirement is that to update the metafields on customer through API but right now i am unable to do that,

Following the document :

https://shopify.dev/docs/api/admin-rest/2023-01/resources/metafield#put-blogs-blog-id-metafields-metafield-id

Screenshot of callout are attached !

Getting the Error:System.HttpResponse[Status=Not Found, StatusCode=404]

Requirement:Update the metafields of customers through the API .

Thanks in Advance

Ashutosh Vijay

Hi There,

The looks like it is going to the right endpoint:

/admin/api/2023-01/customers/{customer_id}/metafields/{metafield_id}.json

What I noticed in your csv file however was that the type was incorrect or all the underscores were replace with spaces for some reason.

{
"metafield":{
    "id":[metafield_id],
    "value":"your value",
    "type":"single_line_text_field",
    }
}

Other than that it should work just fine.

Cheers

Gary

Hi Gary ,

I have already done this ,May be because of some reason the underscore are replace with spaces while uploading the file .

Here is the body attribute which i am sending ::

req.setBody(‘{“metafield”:{“id”:2821554471,“value”:“Indian”,“type”:“single_line_text_field”}}’);

Thanks

the only other thing I can think of is to add “customer_id”:{customer_id} to the json data you send.. though it shouldn’t be required to send the customer id in this case.

Try it anway :slightly_smiling_face: if that doesnt work switch to the tagsAdd graphql mutation thats what I generally use.

Cheers,

Gary

Hi Gary ,

I put the “customer_id”:{customer_id} in json data as well but it does not make some sense .

Can u attach the graphql document link to update the metafields !

Thanks

Hey JP,

Sure, here is the doc to an example on how to add tags to a customer using graphql

Cheers,

Gary