How to change default address for Customer?

New Member
7 0 0

I have a Customer that has 3 addresses (1st is default). I'd like to switch default address from 1st to 2nd. I send 
 

PUT https://{{host}}/admin/customers/{{customerId}}.json
{
	"customer": {
		"id": {{customerId}},
		"addresses": [
			{
				"id": {{addr1Id}},
				"default": false
			},

			{
				"id": "{{addr2Id}}",
				"default": true
			},

			{
				"id": "{{addr3Id}}",
				"default": false
			},
		]
	}
}

This won't helps. Then I decided to provide other fields for all addresses. It also won't work. Next attempt was trying to remove addresses completely by
 

PUT https://{{host}}/admin/customers/{{customerId}}.json
{
	"customer": {
		"id": {{customerId}},
		"addresses": []
	}
}

it also won't work - customer still has all his addresses.

Please, let me know is it possible (and how):
1) setup already existing address as new default one;
2) delete one of customers addresses (by addressId?);
3) store some alias for customers address (i.e. 'home', 'work', 'aunt home')  - it will allow easy switching in 'create-order-form'

0 Likes
Shopify Staff
Shopify Staff
591 0 45

Customers include a default_address field, have you tried using that instead?

1) setup already existing address as new default one;

As I've mentioned, try setting {customer: {default_address: {}}} as the one you want. Be sure you include the id in that field or it made 

2) delete one of customers addresses (by addressId?);

There isn't an API for this yet


3) store some alias for customers address (i.e. 'home', 'work', 'aunt home')  - it will allow easy switching in 'create-order-form'

You can probably pull this off using metafields.

0 Likes
New Member
7 0 0

I've also tried 
 

PUT https://{{host}}/admin/customers/{{customerId}}.json
{
	"customer": {
    	"id": {{customerId}},
		"default_address": {
			"id": {{not-currently-default-id}},
			"default": true
		}
	}
}

it will return 200 (OK) but doesn't change anything in Customer. There is no difference if I provide only addressId or full address fields set here: 200 (OK) and no changes.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
591 0 45

Interesting. I guess that is currently only configurable by the customer account. I'll file an issue and see if we can come up with a decent way of setting the default address via the API.

0 Likes
New Member
7 0 0

You can probably pull this off using metafields.

Yes, it looks like I have to use workaround: add one-per-address Metafield on Customer (so Customer will have addresses.size() metafields).
Something like 

{
	"metafield": {
		"namespace": "addresses",
		"key": "aunt-home",
		"value": "{{address-id}}",
		"value_type": "string",
		"owner": "{{customerId}}",
		"owner_resource": "customer"
	}
}

Unfortunately this is not so easy tasks:

  1. insert new address;
  2. parse response and try to distingish newly created address from old ones (by maximum addressId probably?)
  3. insert new metafield

I'd wish Address will be top-level object like Customer, Shop or Metafield

0 Likes
New Member
7 0 0

2) delete one of customers addresses (by addressId?);

There isn't an API for this yet

I've find out another topic here: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/removing-a-customer-s-address-via-api-...
It looks like Shopify has another API (liquid templates?) that allows Customer address deletion. Unfortunately I don't know how to work with Ruby and 'shopify_api gem' but it looks like some HTTP-based API exist or do I miss something?

0 Likes