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

# Add a card from a token


`POST /v1/payment_methods`

Turns a single-use `paymentToken` (`mtok_…`) from browser capture into a reusable saved card. Needs a customer id (create one at the top of this folder) and a FRESH token — see "Where a payment token comes from" in `00 · Start here`. With the hosted frame not serving yet, this runs once Elements is up.

Auth: a secret key with the `paymentMethods.create` permission. Returns `201` with Payment method.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `customerId` | body | string | Yes | The customer that owns or receives this resource. |
| `paymentToken` | body | string | Yes | A single-use token returned by Myela Elements or an approved card-capture field. |

## Request

**curl**

```curl
curl -X POST "https://payments-api-sandbox.merchantservicedepot.com/v1/payment_methods" \
  -H "Authorization: Bearer $MYELA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "customerId": "{{CUSTOMER_ID}}",
  "paymentToken": "{{PAYMENT_TOKEN}}"
}'
```

**Node**

```node
const res = await fetch("https://payments-api-sandbox.merchantservicedepot.com/v1/payment_methods", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYELA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "customerId": "{{CUSTOMER_ID}}",
    "paymentToken": "{{PAYMENT_TOKEN}}"
  }),
});

if (!res.ok) {
  const { error } = await res.json();
  // Branch on error.code — never on error.message.
  throw new Error(error.code);
}
const data = await res.json();
```

**Python**

```python
import os
import requests

res = requests.post(
    "https://payments-api-sandbox.merchantservicedepot.com/v1/payment_methods",
    headers={
        "Authorization": f"Bearer {os.environ['MYELA_API_KEY']}",
    },
    json={
        "customerId": "{{CUSTOMER_ID}}",
        "paymentToken": "{{PAYMENT_TOKEN}}"
    },
)

if not res.ok:
    # Branch on error["code"] — never on error["message"].
    raise RuntimeError(res.json()["error"]["code"])
data = res.json()
```

## Response

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Unique payment-method identifier. |
| `object` | "payment_method" | Stable resource discriminator. |
| `customerId` | string | Customer that owns this method. |
| `brand` | string | Card brand. |
| `last4` | string | Last four digits only. |
| `expMonth` | integer | Expiration month. |
| `expYear` | integer | Four-digit expiration year. |
| `isDefault` | boolean | Whether this is the customer default. |
| `createdAt` | string | ISO 8601 creation timestamp. |

```json
{
  "id": "pm_01JEXAMPLE",
  "object": "payment_method",
  "customerId": "cus_01JEXAMPLE",
  "brand": "visa",
  "last4": "4242",
  "expMonth": 12,
  "expYear": 2030,
  "isDefault": true,
  "createdAt": "2026-08-10T20:49:51.653Z"
}
```

Source: https://docs.merchantservicedepot.com/api-reference/add-a-card-from-a-token/
