# Update an account

Source: https://developers.swell.is/backend-api/accounts/update-an-account

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

## Arguments

- `id` (objectId, required): Unique identifier for the account.
- `email` (string): Customer's email address.
- `email_optin` (boolean): Indicates the customer opted into email communications.
- `name` (string): Full name of the customer. If `first_name` or `last_name` are updated, then `name` will be automatically updated as a combination of first/last.
- `shipping` (object): Default customer shipping information.
  - `account_address_id` (objectId): Setting this value will populate `shipping` with the associated customer's account address on file.
  - `address1` (string): Shipping address line 1: street address/PO box/company name.
  - `address2` (string): Shipping address line 2: apartment/suite/unit/building.
  - `city` (string): Shipping city/district/suburb/town/village.
  - `country` (string): Two-letter ISO country code.
  - `first_name` (string): Shipping first name. If `name` is updated, then `first_name` will be automatically updated as the first word of the name.
  - `last_name` (string): Shipping last name. If `name` is updated, then `last_name` will be automatically updated as the last words of the name.
  - `name` (string): Shipping full name. If `first_name` or `last_name` are updated, then `name` will be automatically updated as a combination of first/last.
  - `phone` (string): Shipping phone number.
  - `state` (string): Shipping state/county/province/region.
  - `zip` (string): Shipping zip/postal code.
- `billing` (object): Default customer billing information.
  - `account_card_id` (objectId): Setting this value will populate `billing.card` with the associated customer's credit card on file.
  - `address1` (string): Billing address line 1: street address/PO box/company name.
  - `address2` (string): Billing address line 2: apartment/suite/unit/building.
  - `card` (object): Credit card billing details used when `billing.method=card`.
    - `token` (string, required): Token generated by Swell Checkout or Stripe.js.
    - `brand` (string): Credit card brand. Can be `American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
    - `exp_month` (int): Two-digit number representing the credit card expiration month.
    - `exp_year` (int): Four-digit number representing the credit card expiration year.
    - `last4` (string): Last four digits of the card number.
  - `city` (string): Billing city/district/suburb/town/village.
  - `country` (string): Two-letter ISO country code.
  - `first_name` (string): Billing first name. If `name` is updated, then `first_name` will be automatically updated as the first word of the name.
  - `last_name` (string): Billing last name. If `name` is updated, then `last_name` will be automatically updated as the last words of the name.
  - `name` (string): Billing full name. If `first_name` or `last_name` are updated, then `name` will be automatically updated as a combination of first/last.
  - `method` (string): Method of payment. Can be `card`, `account`, or any one of the manual methods defined in payment settings.
  - `phone` (string): Billing phone number.
  - `state` (string): Billing state/county/province/region.
  - `vat_number` (string): VAT number for a business customer associated with this billing method, if applicable.
  - `zip` (string): Billing zip/postal code.
- `currency` (string): Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
- `date_last_order` (date): Date of the last order placed by the customer.
- `first_name` (string): Customer's first name. If `name` is updated, then `first_name` will be automatically updated as the first word of the name.
- `group` (string): Customer group used for special price rules and other customer logic.
- `last_name` (string): If `name` is updated, then `last_name` will be automatically updated as the last words of the name.
- `password` (string): Password used to login and gain access to sensitive information. When the customer has a password, they are required to log in when placing an order using the associated email address. This value is automatically encrypted using bcrypt.
- `password_reset_key` (string): Unique key created when a customer requests a password reset.
- `password_reset_url` (string): When a customer requests password reset, an email is sent with this URL to redirect and authenticate the request.
- `phone` (string): Customer's phone number.
- `type` (enum): Type of customer account. Can be one of `individual` or `business`. Possible values: `individual`, `business`.
- `vat_number` (string): Default VAT number for a `business customer, if applicable.`

## Example request

`PUT /accounts/:id`

**cURL**

```bash
$ curl https://api.swell.store/accounts/62991607782f3b0013cf17af \
  -u store-id:secret-key \
  -d email=sheogorath@shiveringisles.com \
  -X PUT
```

**Node**

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

await swell.put('/accounts/{id}', {
  id: '62991607782f3b0013cf17af',
  email: 'sheogorath@shiveringisles.com'
});
```

**PHP**

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

$swell->put('/accounts/{id}', [
  'id' => '62991607782f3b0013cf17af',
  'email' => 'sheogorath@shiveringisles.com'
]);
```

## Example response

```json
{
  "first_name": "Sheogorath",
  "email": "sheogorath@shiveringisles.com",
  "group": "Deadric princes",
  "currency": "USD",
  "name": "Sheogorath",
  "date_created": "2022-06-02T19:56:55.028Z",
  "type": "individual",
  "order_count": 0,
  "order_value": 0,
  "balance": 50000,
  "id": "62991607782f3b0013cf17af"
}
```
