Solved

Create a new customer with a metafield

Poul_Poulsen
Shopify Partner
23 2 16

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"
      }
    ]
  }
}

 

 

Metafields is a myth...
Accepted Solutions (2)

heyhost
Shopify Partner
106 1 18

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

My enthusiasm greatly exceeds my talent.

View solution in original post

Jason
Shopify Expert
11194 225 2285

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.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 3 (3)

heyhost
Shopify Partner
106 1 18

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

My enthusiasm greatly exceeds my talent.

Jason
Shopify Expert
11194 225 2285

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.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

Poul_Poulsen
Shopify Partner
23 2 16

Ahh now i see, thanks both of you, the GET admin/customers/#{id}/metafields.json worked like a charm 🙂

Metafields is a myth...