Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
According to the documentation i should be able to create a customer with metafields, but i can't seem to get it working.
It creates the customer, but i can't seem to fetch the metafields when asking for the customer by id.
And for some reason there are two identical examples.
Create a new customer with a metafield
POST /admin/customers.json
{
"customer": {
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "steve.lastnameson@example.com",
"phone": "+15142546011",
"verified_email": true,
"addresses": [
{
"address1": "123 Oak St",
"city": "Ottawa",
"province": "ON",
"phone": "555-1212",
"zip": "123 ABC",
"last_name": "Lastnameson",
"first_name": "Mother",
"country": "CA"
}
],
"metafields": [
{
"key": "new",
"value": "newvalue",
"value_type": "string",
"namespace": "global"
}
]
}
}
Solved! Go to the solution
This is an accepted solution.
A random guess but perhaps the namespace is clashing with something else. 'global' is pretty generic. Try changing it to something unique.
If that doesnt work try creating the metafield after the customer (as you will need the customer id) using the Metafield API
/admin/customers/#{id}/metafields.json
This is an accepted solution.
Your JSON post looks fine to me but you might be assuming that the metafield is returned in the response. It's not - only the customer object is returned.
A metafield is a resource linked to the customer object so to get the new metafield you'd need to GET it specifically.
This is an accepted solution.
A random guess but perhaps the namespace is clashing with something else. 'global' is pretty generic. Try changing it to something unique.
If that doesnt work try creating the metafield after the customer (as you will need the customer id) using the Metafield API
/admin/customers/#{id}/metafields.json
This is an accepted solution.
Your JSON post looks fine to me but you might be assuming that the metafield is returned in the response. It's not - only the customer object is returned.
A metafield is a resource linked to the customer object so to get the new metafield you'd need to GET it specifically.
Ahh now i see, thanks both of you, the GET admin/customers/#{id}/metafields.json worked like a charm 🙂