Set/Get default address with the iOS SDK

Highlighted
New Member
5 0 0

I've created an address using the examples in the iOS SDK docs. I can retrieve the address using the SDK as well.

 

However, the default value is not being returned with the SDK. But it is returned with the API. 

 

https://{{api_key}}:{{api_password}}@{{store_name}}.myshopify.com/admin/api/{{api_version}}/customers/{{customer_id}}/addresses.json

Returns the following for one address:

...
"default": true
...

 

But not with the SDK:

 

let query = Storefront.buildQuery { $0
    .customer(customerAccessToken: token) { $0
        .addresses(first: 10) { $0
            .edges { $0
                .node { $0
                    .address1()
                    .address2()
                    .city()
                    .zip()
                    .id()
                }
            }
        }
    }
}

Also, I see no mention of "default" as a possible value: 

https://help.shopify.com/en/themes/liquid/objects/address

 

Finally, using the iOS SDK, how do you set an address as the default? 

 

Thank you. 

 

 

 

0 Likes
Shopify Staff
Shopify Staff
391 53 62

Hey @bfallon,

 

Using the Storefront API, you can get the default address via Customer.defaultAddress:

 

query getDefaultAddress {
  customer(customerAccessToken:"..."){
    defaultAddress {
      id
    }
  }
}

And set with the customerDefaultAddressUpdate mutation. You should be able to translate these for the iOS SDK.

 

Also, I see no mention of "default" as a possible value: 

https://help.shopify.com/en/themes/liquid/objects/address

In liquid, you can get the default address from customer.default_address

 

 

0 Likes