Want to Update MetaFields on Customer through API

JPClouds
Visitor
3 0 0

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

 

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

 

 

Replies 5 (5)

garyrgilbert
Shopify Partner
397 40 163

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

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
JPClouds
Visitor
3 0 0

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

garyrgilbert
Shopify Partner
397 40 163

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 🙂  if that doesnt work switch to the tagsAdd graphql mutation thats what I generally use.

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
JPClouds
Visitor
3 0 0

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 

 

garyrgilbert
Shopify Partner
397 40 163

Hey JP,

 

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

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution