
import AddressFields from "../../../src/reference/subbly-sdk/types/CustomerAddress.mdx";
import AddressPayloadFields from "../../../src/reference/subbly-sdk/types/AddressStorePayload.mdx";

<SdkPage group="addresses" />

Every method here needs a signed-in customer. Sign one in with the
[authentication methods](/reference/subbly-sdk/auth) first.

<Method id="list" signature="subbly.addresses.list()">

Gets every saved address of the signed-in customer.

<Returns type="Promise<CustomerAddress[]>">
The saved addresses. The array is empty when the customer has none.
<Properties label="address" collapsed>
  <AddressFields />
</Properties>
</Returns>

<Example>

```js title="List the addresses"
const addresses = await subbly.addresses.list()
```

</Example>

</Method>

<Method id="store" signature="subbly.addresses.store(payload)">

Creates a new saved address for the signed-in customer. Pass the new `id` to
`subbly.cart.update` as `shippingAddressId` or `billingAddressId`.

<Params>
  <Param name="payload" required type="AddressStorePayload">
    The address to save.

    <Properties label="payload">
      <AddressPayloadFields />
    </Properties>
  </Param>
</Params>

<Returns type="Promise<CustomerAddress>">
The saved address.
<Properties label="address" collapsed>
  <AddressFields />
</Properties>
</Returns>

<Example>

```js title="Add an address"
const address = await subbly.addresses.store({
  firstName: 'Ada',
  lastName: 'Lovelace',
  phone: '+442071234567',
  addressOne: '12 Marylebone Road',
  addressTwo: null,
  city: 'London',
  zip: 'NW1 5JD',
  countryId: 826,
})
```

</Example>

</Method>

<Method id="delete" signature="subbly.addresses.delete(addressId)">

Deletes a saved address. The call fails when the address is still attached to a
subscription.

<Params>
  <Param name="addressId" required type="number">
  ID of the address to delete.
  </Param>
</Params>

<Returns type="Promise<void>">
Nothing. The response body is empty.
</Returns>

<Example>

```js title="Delete an address"
await subbly.addresses.delete(4821)
```

</Example>

</Method>
