# Create a new token

Creating a new token for the payment instrument.

Endpoint: POST /tokens
Version: 1
Security: BasicAuth

## Security:

  - `BasicAuth` (unknown)
    http basic

## Request fields (application/vnd.worldpay.tokens-v1.hal+json):

  - `description` (string)
    A description of your token. If not supplied, a default description is created for you.

  - `tokenExpiryDateTime` (string)
    The date/time after which the token is unavailable, expressed in ISO 8601 format. If not supplied, the default expiry date/time is 7 days in Try and 4 years in the Live environment.We extend the expiry by 7 days or 4 years after any use of the token, if under half of the time remains on the token.

  - `namespace` (string)
    A namespace is used to group up to 16 cards, e.g. for one customer. A card can exist in more than one namespace.

  - `schemeTransactionReference` (string)
    A value provided by Visa or Mastercard which tracks recurring transactions.Note: You are not normally expected to provide a value for schemeTransactionReference. If you are using the [Verified Tokens API](/products/verified-tokens) to create tokens, it is automatically included where applicable.

  - `paymentInstrument` (object, required)
    An object that contains the payment type and details. All sub-fields are mandatory with the exception of billingAddress (see below).

  - `paymentInstrument.type` (string)
    card/front

  - `paymentInstrument.cardHolderName` (string)
    The name on the customer's card.

  - `paymentInstrument.cardExpiryDate` (object)

  - `paymentInstrument.cardExpiryDate.month` (integer, required)

  - `paymentInstrument.cardExpiryDate.year` (integer, required)

  - `paymentInstrument.cardNumber` (string)
    Contains your customer's card number.

  - `paymentInstrument.billingAddress` (object)
    Contains the billing address information.

  - `paymentInstrument.billingAddress.address1` (string, required)

  - `paymentInstrument.billingAddress.postalCode` (string, required)

  - `paymentInstrument.billingAddress.city` (string, required)

  - `paymentInstrument.billingAddress.countryCode` (string, required)

  - `paymentInstrument.billingAddress.address2` (string)

  - `paymentInstrument.billingAddress.address3` (string)

  - `paymentInstrument.billingAddress.state` (string)

  - `merchant` (object, required)
    An object that contains information about your merchant account.

## Request examples:

  - `Creating a Token` (unknown)
    Creating a token from payment instrument

## Response 200:

  - `200` (unknown)
    A token already exists matching the details in the request.

## Response 200 fields (application/vnd.worldpay.tokens-v1.hal+json):

  - `tokenPaymentInstrument` (object, required)

  - `tokenPaymentInstrument.type` (string)

  - `tokenPaymentInstrument.href` (string)

  - `description` (string, required)
    A description of your token. If not supplied, a default description is created for you.

  - `tokenExpiryDateTime` (string, required)
    The date/time after which the token is unavailable, expressed in ISO 8601 format. If not supplied, the default expiry date/time is 7 days in Try and 4 years in the Live environment.We extend the expiry by 7 days or 4 years after any use of the token, if under half of the time remains on the token.

  - `paymentInstrument` (object, required)

  - `paymentInstrument.type` (string)

  - `paymentInstrument.cardNumber` (string, required)
    Contains your customer's card number.

  - `paymentInstrument.cardExpiryDate` (object, required)

  - `paymentInstrument.cardExpiryDate.month` (integer, required)

  - `paymentInstrument.cardExpiryDate.year` (integer, required)

  - `paymentInstrument.cardHolderName` (string)
    The name on the customer's card.

  - `paymentInstrument.billingAddress` (object)
    Contains the billing address information.

  - `paymentInstrument.billingAddress.address1` (string, required)

  - `paymentInstrument.billingAddress.postalCode` (string, required)

  - `paymentInstrument.billingAddress.city` (string, required)

  - `paymentInstrument.billingAddress.countryCode` (string, required)

  - `paymentInstrument.billingAddress.address2` (string)

  - `paymentInstrument.billingAddress.address3` (string)

  - `paymentInstrument.billingAddress.state` (string)

  - `paymentInstrument.networkType` (string)

  - `paymentInstrument.last4Digits` (string)

  - `tokenId` (string)

  - `namespace` (string)

  - `schemeTransactionReference` (string)
    A value provided by Visa or Mastercard which tracks recurring transactions.Note: You are not normally expected to provide a value for schemeTransactionReference. If you are using the [Verified Tokens API](/products/verified-tokens) to create tokens, it is automatically included where applicable.

  - `_links` (object, required)

## Response 200 headers (application/vnd.worldpay.tokens-v1.hal+json):

  - `Accept` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Content-Type` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Location` (string)
    A URI identifying the created token resource.

## Response 201:

  - `201` (unknown)
    A new token was created.

## Response 201 fields (application/vnd.worldpay.tokens-v1.hal+json):

  - `tokenPaymentInstrument` (object, required)

  - `tokenPaymentInstrument.type` (string)
    Indicating the type of this token.

  - `tokenPaymentInstrument.href` (string)
    Link to the corresponding token.

  - `description` (string, required)
    A description of your token. If not supplied, a default description is created for you.

  - `tokenExpiryDateTime` (string, required)
    The date/time after which the token is unavailable, expressed in ISO 8601 format. If not supplied, the default expiry date/time is 7 days in Try and 4 years in the Live environment.We extend the expiry by 7 days or 4 years after any use of the token, if under half of the time remains on the token.

  - `paymentInstrument` (object, required)

  - `paymentInstrument.cardNumber` (string, required)

  - `paymentInstrument.cardExpiryDate` (object, required)

  - `paymentInstrument.cardExpiryDate.month` (integer, required)

  - `paymentInstrument.cardExpiryDate.year` (integer, required)

  - `paymentInstrument.type` (string)

  - `paymentInstrument.cardHolderName` (string)
    The name on the customer's card.

  - `paymentInstrument.billingAddress` (object)

  - `paymentInstrument.billingAddress.address1` (string, required)

  - `paymentInstrument.billingAddress.postalCode` (string, required)

  - `paymentInstrument.billingAddress.city` (string, required)

  - `paymentInstrument.billingAddress.countryCode` (string, required)

  - `paymentInstrument.billingAddress.address2` (string)

  - `paymentInstrument.billingAddress.address3` (string)

  - `paymentInstrument.billingAddress.state` (string)

  - `paymentInstrument.networkType` (string)

  - `paymentInstrument.last4Digits` (string)

  - `tokenId` (string)
    Worldpay's internal identifier for a token. If supplied, must be between 15 and 21 characters, must consist of digits and upper-case characters excluding 'I' and 'O'.

  - `namespace` (string)
    The reference by which a client can identify a shopper. If supplied, must be between 1 and 64 characters, must not start with an underscore, must not contain spaces, '&' or '<'.

  - `schemeTransactionReference` (string)
    A value provided by Visa or Mastercard which tracks recurring transactions.Note: You are not normally expected to provide a value for schemeTransactionReference. If you are using the [Verified Tokens API](/products/verified-tokens) to create tokens, it is automatically included where applicable.

  - `_links` (object, required)

## Response 201 headers (application/vnd.worldpay.tokens-v1.hal+json):

  - `Accept` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Content-Type` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Location` (string)
    A URI identifying the created token resource.

## Response 409:

  - `409` (unknown)
    A token already exists conflicting with some details in the request.

## Response 409 fields (application/vnd.worldpay.tokens-v1.hal+json):

  - `tokenPaymentInstrument` (object, required)

  - `tokenPaymentInstrument.type` (string)
    Indicating the type of this token.

  - `tokenPaymentInstrument.href` (string)
    Link to the corresponding token.

  - `description` (string, required)
    A description of your token. If not supplied, a default description is created for you.

  - `tokenExpiryDateTime` (string, required)
    The date/time after which the token is unavailable, expressed in ISO 8601 format. If not supplied, the default expiry date/time is 7 days in Try and 4 years in the Live environment.We extend the expiry by 7 days or 4 years after any use of the token, if under half of the time remains on the token.

  - `paymentInstrument` (object, required)

  - `paymentInstrument.cardNumber` (string, required)

  - `paymentInstrument.cardExpiryDate` (object, required)

  - `paymentInstrument.cardExpiryDate.month` (integer, required)

  - `paymentInstrument.cardExpiryDate.year` (integer, required)

  - `paymentInstrument.type` (string)

  - `paymentInstrument.cardHolderName` (string)
    The name on the customer's card.

  - `paymentInstrument.billingAddress` (object)

  - `paymentInstrument.billingAddress.address1` (string, required)

  - `paymentInstrument.billingAddress.postalCode` (string, required)

  - `paymentInstrument.billingAddress.city` (string, required)

  - `paymentInstrument.billingAddress.countryCode` (string, required)

  - `paymentInstrument.billingAddress.address2` (string)

  - `paymentInstrument.billingAddress.address3` (string)

  - `paymentInstrument.billingAddress.state` (string)

  - `paymentInstrument.networkType` (string)

  - `paymentInstrument.last4Digits` (string)

  - `paymentInstrument.tokenId` (string)
    Worldpay's internal identifier for a token. If supplied, must be between 15 and 21 characters, must consist of digits and upper-case characters excluding 'I' and 'O'.

  - `paymentInstrument.namespace` (string)
    The reference by which a client can identify a shopper. If supplied, must be between 1 and 64 characters, must not start with an underscore, must not contain spaces, '&' or '<'.

  - `paymentInstrument.schemeTransactionReference` (string)
    A value provided by Visa or Mastercard which tracks recurring transactions.Note: You are not normally expected to provide a value for schemeTransactionReference. If you are using the [Verified Tokens API](/products/verified-tokens) to create tokens, it is automatically included where applicable.

## Response 409 headers (application/vnd.worldpay.tokens-v1.hal+json):

  - `Accept` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Content-Type` (string)
    application/vnd.worldpay.tokens-v1.hal+json

  - `Location` (string)
    A URI identifying the conflicting token resource.

## Response 200 examples:

  - `Creating a token` (unknown)
    A 200 OK response means that you've already tokenized the card and that all data supplied in your create a token request matches the data stored with Access Worldpay.

 Sometimes, a token can be matched even if the data isn't quite the same. For example, if Access Worldpay has a billingAddress on file, the existing billingAddress is retained if no billingAddress was supplied in your request. Additionally, you receive the 200 OK response code.

 The existing token resource reference is returned in the tokenPaymentInstrument object.

## Response 201 examples:

  - `Token Created` (unknown)
    If this is the first time you've tokenized the card, a 201 Created response is returned.

 Your response contains a tokenPaymentInstrument object which contains the href to the token resource. The response also includes next available action links, e.g. updating and deleting the token.

## Response 409 examples:

  - `Conflict` (unknown)
    A 409 Conflict response means that you've already tokenized the card, but some of the data supplied in your create a token request is different from the data in the existing token.

 This conflict could be caused by a differentiation in the cardHolderName, card expiry month, card expiry year billingAddress or schemeTransactionReference (see note below) fields.

 In this case, the data that we have on file is retained. The data which caused the conflict is returned in a conflicts object. If you would like to resolve the conflict, you can update the existing token using the tokens:conflicts action link returned in the response.

