# Accounts

Source: https://developers.swell.is/frontend-api/accounts

**Swell.js:**

Methods to set up and update a customer's account data.

### Create an account

Use to create a new customer account and attach it to the current session.

Returns the newly created account object.

**Create an account**

**swell.js**

```javascript
await swell.account.create({
  email: 'julia@example.com',
  first_name: 'Julia', // Optional
  last_name: 'Sanchez', // Optional
  email_optin: true, // Optional
  password: 'thepassword' // Optional
})
```

### Update the account

Use to update properties of the account that is currently logged in.

Returns the updated account object if successful. Otherwise, returns a validation error.

**Update the account**

**swell.js**

```javascript
await swell.account.update({
  email: 'julia@example.com',
  first_name: 'Julia',
  last_name: 'Sanchez',
  email_optin: true
})
```

### Update the account metadata

Use the `metadata` object to store arbitrary values on an account. As opposed to storing custom fields with the [Backend API](https://developers.swell.is/backend-api/introduction), the metadata object is publicly accessible, making it easy to add custom data throughout your customer flow. Note: the `metadata` object can also be queried and updated using the Backend API.

Returns the updated account object.

**Update the account metadata**

**swell.js**

```javascript
await swell.account.update({
  metadata: {
    any: 'value',
    even: {
      nested: true
    }
  }
})
```

When updating nested arrays in metadata, you may notice the default behavior is to merge instead of replacing values. To replace array values, use the `$set` operator to override the entire value.

**Replace array values for account updates**

**swell.js**

```javascript
await swell.account.update({
  $set: {
    metadata: {
      my_array: [ ... ]
    }
  }
})
```

**GraphQL:**

Methods to set up a customer's account data.

### Create an account

Use to create a new customer account and attach it to the current session.

Returns the newly created account object. The parameter for this mutation is `input` (required).

**Create an account**

**GraphQL**

```graphql
mutation createAccount {
  createAccount(
    input: {
      firstName: "Ancotar"
      email: "ancotar@fortcaractacus.net"
      emailOptin: true
    }
  ) {
    firstName
    email
    emailOptin
  }
}
```
