---
title: "Tokenize a sealed card"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.nicer.travel/llms.txt
> Use this file to discover all available pages before exploring further.

# Tokenize a sealed card

Path: Nicer API › tokenization

`POST /tokenization`

URL: `https://api.nicer.travel/tokenization`

Opens a card envelope the checkout sealed in the browser to the card intake key, validates the card and stores it encrypted, and answers its brand, last four digits and payment method id. Any signed-in person may call it: commerce authorizes the card for them before the envelope is opened. The same handler serves `POST /tokenization/payment-link` for a payment-link session.

## Authentication

- `bearerAuth`, http bearer, header `Authorization`, format `JWT`

## Request body

_Required._

- `sealed` (`tokenization.create.sealed`; object, required)
  - `v` (`tokenization.create.sealed.v`; number, required)
  - `alg` (`tokenization.create.sealed.alg`; string, required)
  - `kid` (`tokenization.create.sealed.kid`; string, required)
    - minLength: `1`
  - `wrappedKey` (`tokenization.create.sealed.wrappedKey`; string, required)
    - minLength: `1`
  - `nonce` (`tokenization.create.sealed.nonce`; string, required)
    - minLength: `1`
  - `ciphertext` (`tokenization.create.sealed.ciphertext`; string, required)
    - minLength: `1`
- `paymentMethodId` (`tokenization.create.paymentMethodId`; string, optional)
  - pattern: `^paym_.*`
- `saveMethod` (`tokenization.create.saveMethod`; boolean, optional)
- `saveOnly` (`tokenization.create.saveOnly`; boolean, optional)

## Example request

```json
{
  "sealed": {
    "v": 1,
    "alg": "RSA-OAEP-256+A256GCM",
    "kid": "string",
    "wrappedKey": "string",
    "nonce": "string",
    "ciphertext": "string"
  },
  "paymentMethodId": "string",
  "saveMethod": true,
  "saveOnly": true
}
```

## Code samples

### JavaScript SDK

```javascript
import { createClient } from "@nicertravel/sdk";

const nicer = createClient({
  baseUrl: "https://api.nicer.travel",
  token: process.env.NICER_TOKEN,
});

await nicer.tokenization.create({
  "sealed": {
    "v": 1,
    "alg": "RSA-OAEP-256+A256GCM",
    "kid": "string",
    "wrappedKey": "string",
    "nonce": "string",
    "ciphertext": "string"
  }
});
```

### Nicer CLI

```bash
nicer tokenization create --input - <<'JSON'
{
  "sealed": {
    "v": 1,
    "alg": "RSA-OAEP-256+A256GCM",
    "kid": "string",
    "wrappedKey": "string",
    "nonce": "string",
    "ciphertext": "string"
  }
}
JSON
```

### cURL

```bash
curl --request POST \
  --url https://api.nicer.travel/tokenization \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "sealed": {
    "v": 1,
    "alg": "RSA-OAEP-256+A256GCM",
    "kid": "string",
    "wrappedKey": "string",
    "nonce": "string",
    "ciphertext": "string"
  },
  "paymentMethodId": "string",
  "saveMethod": true,
  "saveOnly": true
}
'
```

### TypeScript

```typescript
const url = 'https://api.nicer.travel/tokenization';
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer <token>'
  },
  body: JSON.stringify({
    sealed: {
      v: 1,
      alg: 'RSA-OAEP-256+A256GCM',
      kid: 'string',
      wrappedKey: 'string',
      nonce: 'string',
      ciphertext: 'string'
    },
    paymentMethodId: 'string',
    saveMethod: true,
    saveOnly: true
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.nicer.travel/tokenization"

payload = {
    "sealed": {
        "v": 1,
        "alg": "RSA-OAEP-256+A256GCM",
        "kid": "string",
        "wrappedKey": "string",
        "nonce": "string",
        "ciphertext": "string"
    },
    "paymentMethodId": "string",
    "saveMethod": True,
    "saveOnly": True
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

OK

#### Example

```json
{
  "brand": "visa",
  "last4": "string",
  "paymentCredentialId": "string",
  "paymentMethodId": "string",
  "source": "NICER#AUTHORIZATION_FORM"
}
```

- `brand` (`tokenization.create.response.200.brand`; string, required)
  - one of `"visa"`, `"mastercard"`, `"amex"`, `"discover"`, `"unionpay"`
- `last4` (`tokenization.create.response.200.last4`; string, required)
  - pattern: `^\d{4}$`
- `paymentCredentialId` (`tokenization.create.response.200.paymentCredentialId`; any of, required)
  - any of the following: `string`, `null`
- `paymentMethodId` (`tokenization.create.response.200.paymentMethodId`; string, required)
  - pattern: `^paym_.*`
- `source` (`tokenization.create.response.200.source`; string, required)
  - one of `"NICER#AUTHORIZATION_FORM"`, `"NICER#PAYMENT_LINK"`

### 400

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`tokenization.create.response.400.errorCode`; string, required)
- `errorMessage` (`tokenization.create.response.400.errorMessage`; string, required)

### 401

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`tokenization.create.response.401.errorCode`; string, required)
- `errorMessage` (`tokenization.create.response.401.errorMessage`; string, required)

### 403

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`tokenization.create.response.403.errorCode`; string, required)
- `errorMessage` (`tokenization.create.response.403.errorMessage`; string, required)


Source: https://docs.nicer.travel/api/tokenization/tokenization.create/index.md
