Search code examples
addressbookregioncountryspartacus-storefront

how to get the FULL details for the current user using UserService, including their default address?


The default address data returned contains country and region codes, but not country and region names. Any one know if there's a way to do that in Spartacus, or would that be something custom?


Solution

  • Good question! You can use Spartacus's configurable endpoint mechanism to achieve this.

    For your particular case, you would want to override the addressDetail and addresses endpoints. You will need to add the FULL fields for country and regions your endpoints will look like this:

        addresses: 'users/${userId}/addresses?fields=DEFAULT,addresses(country(FULL),region(FULL))',
        addressDetail: 'users/${userId}/addresses/${addressId}?fields=country(FULL),region(FULL)',
    

    Alternatively, you could just add fields=FULL to receive ALL the available details.