# Account addresses

Source: https://developers.swell.is/backend-api/account-addresses

The account addresses collection is stored on the account model. It houses a customer's address information and supports several entries which can be used for shipping and billing purposes.

## The account address model

### Fields

- `id` (objectId): Unique identifier for the address.
- `active` (boolean): Whether the address is active on the account. Inactive accounts will not be returned in the [Storefront API](https://developers.swell.is/frontend-api/introduction). Default: `true`.
- `address1` (string, required): Primary street address.
- `address2` (string): Secondary street address.
- `city` (string): City where the address is located.
- `country` (string): Country of the residence.
- `date_created` (date): Date of the address creation.
- `date_updated` (date): Date the address was updated.
- `fingerprint` (string): A unique fingerprint hashed from specific address fields that is used to prevent duplicate entries.
- `first_name` (string): First name listed for the address.
- `last_name` (string): Last name listed for the address.
- `name` (string): Combined name listed for the address.
- `parent_id` (objectId, required): The corresponding account `id` for the address.
- `parent` (Account): Expandable link to the customer's account.
- `phone` (string): Phone number listed for the address.
- `state` (string): State of the address.
- `tax_id` (string): Tax identification number of the recipient, where required for customs or delivery.
- `zip` (string): Postal code of the address.

### Example response

```json
{
  "parent_id": "6296b0ad8f4d1100129e16c3",
  "name": "Adoring Fan",
  "first_name": "Adoring",
  "last_name": "Fan",
  "address1": "The Arena",
  "address2": "Arena District",
  "city": "Imperial City",
  "state": "CA",
  "zip": "94104",
  "country": "US",
  "phone": null,
  "company": null,
  "fingerprint": "92f130033566d9846522759d54cbf5e5",
  "date_created": "2022-06-07T13:35:12.281Z",
  "active": true,
  "id": "62acbbe0d69a3b0012c7eae5"
}
```


## Create an account address

Create a new customer account address.

### Arguments

- `id` (objectId): Unique identifier for the address.
- `active` (boolean): Whether the address is active on the account. Inactive accounts will not be returned in the [Storefront API](https://developers.swell.is/frontend-api/introduction). Default: `true`.
- `parent_id` (objectId, required): The corresponding account `id` for the address.
- `address1` (string, required): Primary street address.
- `address2` (string): Secondary street address.
- `city` (string): City where the address is located.
- `company` (string): Customer's company name, if applicable.
- `country` (string): Country of the residence.
- `date_created` (date): Date of the address creation.
- `date_updated` (date): Date the address was updated.
- `fingerprint` (string): A unique fingerprint hashed from specific address fields that is used to prevent duplicate entries.
- `first_name` (string): First name listed for the address.
- `last_name` (string): Last name listed for the address.
- `name` (string): Combined name listed for the address.
- `parent` (Account): Link to the parent account.
- `phone` (string): Phone number listed for the address.
- `state` (string): State of the address.
- `zip` (string): Postal code of the address.

### Example request

`POST /accounts:addresses`

**cURL**

```sh
$ curl https://api.swell.store/accounts:addresses \
  -u store-id:secret-key \
  -d email= "adoringfan@azurasstar.com" \
  -d first_name="Adoring" \
  -d last_name="Fan" \
  -d address1="123 Breezehome St" \
	-d city="Whiterun" \
	-d country="US" \
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/accounts:addresses', {
  email: 'adoringfan@azurasstar.com',
  first_name: 'Adoring'
  last_name: 'Fan'
	address1: '123 Breezehome St'
	city: 'Whiterun'
	country: 'US'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/accounts:addresses', [
  'email' => 'adoringfan@azurasstar.com',
  'first_name' => 'Adoring'
  'last_name' => 'Fan'
  'address1' => '123 Breezehome St'
	'city' => 'Whiterun'
	'country' => 'US'
]);
```

### Example response

```json
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "name": "Adoring Fan",
      "first_name": "Adoring",
      "last_name": "Fan",
      "address1": "123 Breezehome St",
      "address2": null,
      "city": "Whiterun",
      "state": "NY",
      "zip": null,
      "country": "US",
      "phone": null,
      "company": "Honningbrew Meadery",
      "fingerprint": "1219483071269e91f9528ac1c4237944",
      "date_created": "2022-07-12T17:53:55.762Z",
      "active": true,
      "id": "62cdb5332c0a5f00123c5fd7"
    }
```


## Retrieve an account address

Retrieve an existing account address using the ID that was returned when created.

### Arguments

- `id` (objectId, required): Unique identifier for the address.

### Example request

`GET /accounts:addresses/:id`

**cURL**

```sh
$ curl https://api.swell.store/accounts:addresses/62cdb5332c0a5f00123c5fd7 \
  -u store-id:secret-key
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/accounts:addresses/{id}', {
  id: '62cdb5332c0a5f00123c5fd7'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/accounts:addresses/{id}', [
  'id' => '62cdb5332c0a5f00123c5fd7'
]);
```

### Example response

```json
{
  "parent_id": "621e53a6213eaf013d1fa6b2",
  "name": "Njada Stonearm",
  "first_name": "Njada",
  "last_name": "Stonearm",
  "address1": "123 Breezehome St",
  "address2": null,
  "city": "Whiterun",
  "state": "NY",
  "zip": null,
  "country": "US",
  "phone": null,
  "fingerprint": "1219483071269e91f9528ac1c4237944",
  "date_created": "2022-07-12T17:53:55.762Z",
  "active": true,
  "id": "62cdb5332c0a5f00123c5fd7"
}
```


## Update an account address

Update an existing account address using the ID that was returned when created.

### Arguments

- `id` (objectId, required): Unique identifier for the address.
- `parent_id` (objectId, required): The ID of the parent customer.
- `address1` (string, required)
- `city` (string): City where the address is located.
- `company` (string): Customer's company name, if applicable.
- `country` (string): Country of the residence.
- `first_name` (string): First name listed for the address.
- `last_name` (string): Last name listed for the address.
- `name` (string): Combined name listed for the address.
- `state` (string): State of the address.
- `zip` (string): Postal code of the address.

### Example request

`PUT /accounts:addresses/:id`

**cURL**

```sh
$ curl https://api.swell.store/accounts:addresses/62cdb5332c0a5f00123c5fd7 \
  -u store-id:secret-key \
  -d address1="456 Breezehome St" \
  -X PUT
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.put('/accounts:addresses/{id}', {
  id: '62cdb5332c0a5f00123c5fd7',
  address1: '456 Breezehome St'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->put('/accounts:addresses/{id}', [
  'id' => '62cdb5332c0a5f00123c5fd7',
  'address1' => '456 Breezehome St'
]);
```

### Example response

```json
{
  "parent_id": "621e53a6213eaf013d1fa6b2",
  "name": "Njada Stonearm",
  "first_name": "Njada",
  "last_name": "Stonearm",
  "address1": "456 Breezehome St",
  "address2": null,
  "city": "Whiterun",
  "state": "NY",
  "zip": null,
  "country": "US",
  "phone": null,
  "fingerprint": "1219483071269e91f9528ac1c4237944",
  "date_created": "2022-07-12T17:53:55.762Z",
  "date_updated": "2022-07-14T10:22:41.318Z",
  "active": true,
  "id": "62cdb5332c0a5f00123c5fd7"
}
```


## List all account addresses

Return a list of customer account addresses.

### Arguments

- `expand` (string): Expand link fields and child collections by using the expand argument.

  - For example, `expand=account` would return a related customer account if one exists.

  When the field represents a collection, you can specify the query limit.

  - For example, `expand=variants:10` would return up to 10 records of the variants collection.

  See [expanding](https://developers.swell.is/backend-api/querying/expanding) for more details.
- `fields` (string): Returns only the specified fields in the result.

  - For example `fields=name,slug` would return only the fields `name` and `slug` in the response.

  Supports nested object and array fields using dot-notation.

  - For example, `items.product_id`. The product `id` is always returned.
- `include` (object): Include one or more arbitrary queries in the response which are potentially related to the main query.

  See [including](https://developers.swell.is/backend-api/querying/including) for more details.
- `limit` (int): Limit the number of records returned, ranging between `1` and `1000`. Defaults to `15`. Default: `15`.
- `page` (int): The page number of results to return given the specified or default `limit`.
- `search` (string): A text search is performed using the search argument. Searchable fields are defined by the model.

  - For example, `search=red` would return records containing the word "red" anywhere in the defined text fields.

  See [searching](https://developers.swell.is/backend-api/querying/searching) for more details.
- `sort` (string): Expression to sort results by using a format similar to a SQL sort statement.

  - For example, `sort=name asc` would return records sorted by name ascending.

  See [sorting](https://developers.swell.is/backend-api/querying/sorting) for more details.
- `where` (object): An object with criteria to filter the result.

  - For example, `active=true` would return records containing a field `active` with the value `true`.

  It's also possible to use query operators, for example, `$eq`, `$ne`, `$gt`, and more.

  See [querying](https://developers.swell.is/backend-api/querying) for more details.

### Example request

`GET /accounts:addresses`

**cURL**

```sh
$ curl https://api.swell.store/accounts:addresses/ \
  -u store-id:secret-key \
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/accounts:addresses/', {
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/accounts:addresses/', [
]);
```

### Example response

```json
{
  "count": 1,
  "results": [
    {
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "name": "Njada Stonearm",
      "first_name": "Njada",
      "last_name": "Stonearm",
      "address1": "123 Breezehome St",
      "address2": null,
      "city": "Whiterun",
      "state": "NY",
      "zip": null,
      "country": "US",
      "phone": null,
      "company": "Honningbrew Meadery",
      "fingerprint": "1219483071269e91f9528ac1c4237944",
      "date_created": "2022-07-12T17:53:55.762Z",
      "active": true,
      "id": "62cdb5332c0a5f00123c5fd7"
    }
  ],
  "page": 1,
  "page_count": 1,
  "limit": 15
}
```


## Delete an account address

Deleting account addresses with the Swell Backend API.

### Arguments

- `id` (objectId, required): The id of the account address to delete.

### Example request

`DELETE /accounts:addresses/:id`

**cURL**

```sh
$ curl https://api.swell.store/accounts:addresses/62e047aaff9aae0013394b22 \
  -u store-id:secret-key \
  -X DELETE
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.delete('/accounts:addresses/{id}', {
  id: '62e047aaff9aae0013394b22'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->delete('/accounts:addresses/{id}', [
  'id' => '62e047aaff9aae0013394b22'
]);
```

### Example response

```json
{
  "parent_id": "62e046da033fc8001271fc74",
  "name": "Jzargo Khajiit",
  "first_name": "Jzargo",
  "last_name": "Khajiit",
  "address1": "321 Skyrim Way",
  "address2": null,
  "city": "Winterhold",
  "state": "NY",
  "zip": null,
  "country": "US",
  "phone": null,
  "fingerprint": "ee9f59a3b941ea09513058efdb108b6d",
  "date_created": "2022-07-26T19:59:38.141Z",
  "active": true,
  "id": "62e047aaff9aae0013394b22"
}
```

