> Index of every page: https://docs.merchantservicedepot.com/llms.txt

# Customers and addresses

> Store the people you charge, their addresses, and the cards they've saved.

A customer is the record that saved cards, addresses, subscriptions, and invoices hang off. Create the customer first, then attach cards and addresses to it.

## Create a customer

Create a customer with `POST /v1/customers`. Only `email` is required. Add your own `externalId` so you can find the customer again by the id you already use.

**Node**

```ts title="server.ts"
const customer = await myela.gateway.customers.create({
  email: 'ada@example.com',
  name: 'Ada Lovelace',
  externalId: 'crm_42', // your own id for them
  customFields: [{ name: 'tier', type: 'text', value: 'gold' }],
});
```

**cURL**

```bash title="terminal"
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/customers \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ada@example.com",
    "name": "Ada Lovelace",
    "externalId": "crm_42",
    "customFields": [{ "name": "tier", "type": "text", "value": "gold" }]
  }'
```

| Field | Required | Means |
| --- | --- | --- |
| `email` | Yes | Unique among your active customers. A duplicate is 409 SHOPPER_EMAIL_EXISTS. |
| `name` | No | Defaults to the part of the email before the @. |
| `phone` | No | The customer's phone number. |
| `externalId` | No | Your own id for them, 1 to 255 characters. Unique among your active customers. |
| `customFields` | No | Up to 20 typed fields of your own. See below. |

The response is the customer: `id` (`cus_…`), `email`, `name`, `phone`, `externalId`, `customFields`, and `createdAt`. `customFields` is left out when empty. A second customer with the same `externalId` is `409 SHOPPER_EXTERNAL_ID_EXISTS`. To load many at once, see [Bulk jobs](https://docs.merchantservicedepot.com/docs/payments/bulk-jobs/).

## Find a customer

There are three ways to look a customer up. Use `?externalId=` for an exact match on your own id; that's the one for programs. Use `?q=` for a case-insensitive search over name and email; that's the one for people. Or fetch by Myela's id with `GET /v1/customers/{id}`.

**Node**

```ts title="server.ts"
// Find them again by your id, without storing ours.
const found = await myela.gateway.customers.list({ externalId: 'crm_42' });

// Or search their details.
await myela.gateway.customers.list({ q: 'ada' });
```

**cURL**

```bash title="terminal"
# By your own id (exact match)
curl "https://payments-api-sandbox.merchantservicedepot.com/v1/customers?externalId=crm_42" \
  -H "Authorization: Bearer myela_sk_test_…"

# By name or email (substring)
curl "https://payments-api-sandbox.merchantservicedepot.com/v1/customers?q=ada" \
  -H "Authorization: Bearer myela_sk_test_…"

# By Myela's id
curl https://payments-api-sandbox.merchantservicedepot.com/v1/customers/{id} \
  -H "Authorization: Bearer myela_sk_test_…"
```

The id in the path is always Myela's `cus_…`. Your own id there is a `404`, so use `?externalId=` instead. A search with `?q=` can match several customers, so don't take the first result in automation. A malformed or repeated `?externalId=` is a `422`, not an empty filter.

Lists return 10 customers by default and up to 100 with `limit`. Pass the last id you have as `startingAfter` for the next page. More in [Pagination](https://docs.merchantservicedepot.com/docs/platform/pagination/).

## Update a customer

Update with `POST /v1/customers/{id}`, not `PATCH`. Send only the fields that change. A new email that another active customer already has is `409 SHOPPER_EMAIL_EXISTS`.

```bash title="terminal"
# Only the fields you send change
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/customers/{id} \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Ada King" }'
```

`externalId` is write-once. Sending the same value again does nothing, but changing it is `409 SHOPPER_EXTERNAL_ID_IMMUTABLE`. Once a customer is deleted, their `externalId` is free to use again.

### Custom fields

`customFields` holds up to 20 fields of your own, each a `name`, `type`, and `value`. Names are 1 to 40 characters, start with a letter, and must be unique, ignoring case. Writing the array replaces the whole thing, so send every field you want to keep. Send `null` or `[]` to clear it. A bad row is `422 CUSTOM_FIELD_INVALID`.

| type | value |
| --- | --- |
| `text` | A string of up to 500 characters. |
| `number` | A decimal sent as a string, for example "12". Up to 50 characters. |
| `boolean` | true or false. |
| `date` | A date as YYYY-MM-DD. |

```bash title="terminal"
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/customers \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
  "email": "ada@example.com",
  "customFields": [
    { "name": "Plan tier", "type": "text",    "value": "gold" },
    { "name": "Seats",     "type": "number",  "value": "12" },
    { "name": "VIP",       "type": "boolean", "value": true },
    { "name": "Renewal",   "type": "date",    "value": "2027-01-31" }
  ]
}'
```

Custom fields aren't searchable, and they stay inside Myela.

## Addresses

An address belongs to one customer. Create it with `POST /v1/addresses`. `customerId` is the only required field. Every other field is optional, but any field you send must be a non-empty string. Fields that aren't on the list below are dropped.

**Node**

```ts title="server.ts"
const address = await myela.gateway.addresses.create({
  customerId: customer.id,
  line1: '1 Analytical Way',
  city: 'London',
  postalCode: 'EC1A 1BB',
  country: 'GB',
});
```

**cURL**

```bash title="terminal"
# Create
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/addresses \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "cus_…",
    "line1": "1 Analytical Way",
    "city": "London",
    "postalCode": "EC1A 1BB",
    "country": "GB"
  }'

# Every address for a customer, in one response
curl "https://payments-api-sandbox.merchantservicedepot.com/v1/addresses?customerId=cus_…" \
  -H "Authorization: Bearer myela_sk_test_…"
```

| Field | Means |
| --- | --- |
| `customerId` | Required when you create the address. An unknown customer is 404 SHOPPER_NOT_FOUND. |
| `firstName, lastName, company` | Who the address is for. |
| `line1, line2, city, state, postalCode, country` | Where it is. |
| `email, phone` | How to reach them at this address. |

`GET /v1/addresses?customerId=…` returns every address for the customer in one response. It never pages, and `hasMore` is always `false`. Read one address with `GET /v1/addresses/{id}`, and update it with `POST /v1/addresses/{id}`, sending only the fields that change.

### Default billing and shipping

Mark an address as the customer's default with `POST /v1/addresses/{id}/default`. `type` is required and must be `billing` or `shipping`; anything else is a `422`. The two defaults are independent, so an address is both only if you call twice. When an invoice is issued, it copies the billing default into `billTo`.

**Node**

```ts title="server.ts"
// `type` is required. Billing and shipping defaults are independent, so an
// address serves as both only by calling twice.
await myela.gateway.addresses.setDefault(address.id, 'billing');
```

**cURL**

```bash title="terminal"
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/addresses/{id}/default \
  -H "Authorization: Bearer myela_sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{ "type": "billing" }'
```

## Saved cards

Cards attach to a customer with `POST /v1/payment_methods`, and `GET /v1/payment_methods?customerId=…` lists them. When you charge a saved card, the payment belongs to the card's owner. The whole flow, from token to charge, is in [Save a card, then charge it](https://docs.merchantservicedepot.com/docs/payments/save-a-card/).

## Deleting

Deleting a customer, a saved card, or an address is off by default on every key. Until Myela grants it, the call answers `403 capability_not_enabled`, and `GET /v1/capabilities` reports it as `unavailable`. On an account that can't do the operation at all, the answer is `501` instead.

| Route | Once granted |
| --- | --- |
| `DELETE /v1/customers/{id}` | Refused with 409 SHOPPER_HAS_ACTIVE_SUBSCRIPTIONS while the customer has active subscriptions. Otherwise revokes every saved card, then deletes the customer. |
| `DELETE /v1/payment_methods/{id}` | Refused with 409 CARD_HAS_ACTIVE_SUBSCRIPTIONS while a subscription uses the card. |
| `DELETE /v1/addresses/{id}` | Deletes the address. |

A delete that goes through answers `204` with no body.

> **Deleting needs Myela** [Talk to us](https://docs.merchantservicedepot.com/sign-in/#request)

Deletes aren't self-serve. Your Myela contact can enable them for your key.

Source: https://docs.merchantservicedepot.com/docs/payments/customers/
