Skip to main content
Detokenization is a paid feature. It isn’t enabled by default, and is enabled manually for each merchant account. To request access and pricing, contact your account manager.
Detokenization returns the card number and expiration date of a card stored in the vault. The platform encrypts the card details to a public key that you provide. Only a system that holds the matching private key can read them. Use detokenization when your own PCI-compliant systems need the card details of a stored card. If you only need to send card data to a third-party endpoint, use Vault Forwarding instead. Vault Forwarding sends the card data to the endpoint directly, so it never reaches your systems.

Prerequisites

Detokenization is enabled manually for each merchant account. To get started, contact your account manager and provide the following:
  • Agreement: A contract that includes the detokenization fee. Each successful detokenization request is charged.
  • Attestation of Compliance: A current PCI DSS Attestation of Compliance (AoC) for the environment that decrypts the card data.
  • Public key: An RSA public key in PEM format. The key must be at least 2048 bits, and 3072 bits is recommended. Elliptic curve (EC) keys aren’t supported. See Create a key pair.
You also agree on a key ID with your account manager. The platform sets it as the kid header of every encrypted payload, so you can select the matching private key. The platform records an expiry date for your AoC and for your public key. After either date passes, requests fail with a 403 error. Send your account manager a renewed AoC or a new public key before the current one expires. You can’t upload or replace the public key through the API.

Create a key pair

Create the key pair in the environment that your AoC covers. The private key must never leave that environment. This key pair is separate from your API key pair. API keys use elliptic curve keys, but the detokenization key must be an RSA key. Generate a 3072-bit RSA private key:
Export the matching public key:
Check that the public key is an RSA key of at least 2048 bits:
The output must be Public-Key: (3072 bit), or a size of 2048 bits or more. If the output is Not an RSA key, create a new RSA key pair. You can also create the key pair in a hardware security module (HSM) or a key management service (KMS). The service must export the public key as an RSA public key in PEM format, and must decrypt with RSA-OAEP-256.

Send the public key to your account manager

Send only the public key file to your account manager. Never send the private key. If you send a private key by mistake, create a new key pair. Before the key is activated, its fingerprint is confirmed with a contact named on your AoC, on a different channel from the one that sent the key. To get the fingerprint, run:
To replace a key, create a new key pair and agree a new key ID with your account manager. Keep the old private key until you decrypt every payload that uses it.

Grant access to an API key

The endpoint requires the payment-methods.detokenization.read scope. Assign the Detokenization role to the API key that calls it. This role grants that scope and nothing else. For more information, see The Detokenization role. Only API keys can detokenize a card. Requests from a dashboard session are refused, even for an Administrator.

Request

Send a POST request with no body. Set the X-Gr4vy-Merchant-Account-Id header to the merchant account that stores the payment method.
The private key in these examples is the key of your API key pair, which signs the request. It isn’t the private key that decrypts the payload.

Response

A successful request returns the card details as an encrypted payload.

Decrypt the payload

The protected header of the JWE contains these values. Decrypt the payload with the private key that matches your public key. Accept only the RSA-OAEP-256 and A256GCM algorithms.
The decrypted payload is a JSON object.
Check that merchant_account_id and payment_method_id match the request before you use the card details.

Errors

Rate limits

The platform limits detokenization requests for each merchant account over a moving 60-second window. The default limit is 300 requests in each window. A different limit can be set for your merchant account. When you reach the limit, the API returns a 429 error with a Retry-After header of 60. Wait that number of seconds before you retry. Refused requests also count toward the limit, for example 400 and 404 errors. Requests that return a 429 error don’t count.

Security

  • One card for each request: Each request returns one card. There is no bulk endpoint.
  • No security code: The payload never contains the card security code (CVV).
  • No network tokens: The payload contains the card number only, never a network token or cryptogram.
  • No caching: Successful responses include a Cache-Control: no-store header.
  • Keep the private key in your PCI environment: The platform only holds your public key. Store the private key in the environment that your AoC covers, and decrypt the payload only there.
  • Use a dedicated API key: Give the Detokenization role to a key that only your PCI-compliant systems use. This lets you revoke card access without affecting your other integrations.

API reference

The following API endpoints relate to this guide.