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

# Create a Card Registration

[Read more about the Card Registration object →](/api-reference/card-registrations/card-registration-object)

### Body parameters

<ParamField body="Tag" type="string">
  Custom data that can be added to this object.\
  In the case of the Card Registration, this parameter can be used to facilitate the link between the User object and its equivalent on your platform for instance. This value will be inherited by the Card object `Tag` parameter and will not be editable.
</ParamField>

<ParamField body="UserId" type="string" required>
  The unique identifier of the user the card belongs to.
</ParamField>

<ParamField body="CardType" type="string">
  **Allowed values:** `CB_VISA_MASTERCARD`, `AMEX`, `MAESTRO`, `BCMC`

  **Default value:** `CB_VISA_MASTERCARD`

  The type of the card. If not supplied, the default value will be taken into account.
</ParamField>

<ParamField body="Currency" type="string" required>
  **Allowed values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

  The currency of the card.
</ParamField>

### Responses

<AccordionGroup>
  <Accordion title="200">
    <ResponseField name="Id" type="string">
      The unique identifier of the Card Registration object.
    </ResponseField>

    <ResponseField name="Tag" type="string">
      Custom data that can be added to this object.\
      In the case of the Card Registration, this parameter can be used to facilitate the link between the User object and its equivalent on your platform for instance. This value will be inherited by the Card object `Tag` parameter and will not be editable.
    </ResponseField>

    <ResponseField name="CreationDate" type="Unix timestamp">
      The date and time at which the object was created.
    </ResponseField>

    <ResponseField name="AccessKey" type="string">
      The secure value to use when tokenizing the card via the dedicated endpoint.
    </ResponseField>

    <ResponseField name="PreregistrationData" type="string">
      The secure value to identify the registration when tokenizing the card via the dedicated endpoint.
    </ResponseField>

    <ResponseField name="RegistrationData" type="string">
      The string returned by the tokenization server, which must be sent in full as the `RegistrationData` on the <a href="/api-reference/card-registrations/update-card-registration">PUT Update a Card Registration</a> endpoint to create the Card object.
    </ResponseField>

    <ResponseField name="CardId" type="string">
      The unique identifier of the Card object, which is returned after updating the Card Registration object with the `RegistrationData`.
    </ResponseField>

    <ResponseField name="CardType" type="string">
      **Returned values:** `CB_VISA_MASTERCARD`, `AMEX`, `MAESTRO`, `BCMC`

      **Default value:** `CB_VISA_MASTERCARD`

      The type of the card. If not supplied, the default value will be taken into account.
    </ResponseField>

    <ResponseField name="CardRegistrationURL" type="string">
      The URL to make the card tokenization call.

      **Caution:** This variable URL is specific to each card registration. You must rely on the returned URL in full (host, path, and queries) and not hardcode any part of it.
    </ResponseField>

    <ResponseField name="ResultCode" type="string">
      The code indicating the result of the operation. This information is mostly used to <a href="/errors/codes">handle errors</a> or for filtering purposes.
    </ResponseField>

    <ResponseField name="ResultMessage" type="string">
      The explanation of the result code.
    </ResponseField>

    <ResponseField name="Currency" type="string">
      **Returned values:** The three-letter <a href="/api-reference/overview/data-formats" target="_blank">ISO 4217 code</a> (EUR, GBP, etc.) of a <a href="/guides/currencies" target="_blank">supported currency</a> (depends on feature, contract, and activation settings).

      The currency of the card.
    </ResponseField>

    <ResponseField name="Status" type="string">
      **Returned values:** `CREATED`, `VALIDATED`, `ERROR`

      The status of the card registration:

      * `CREATED` – The card registration has been created, but no `RegistrationData` has been entered yet and the `CardId` value is `null`.
      * `VALIDATED` – The card registration has been successfully updated with the `RegistrationData` from the tokenization server.
      * `ERROR` – The card registration couldn’t be updated with the `RegistrationData` and no `CardId` was generated. For more information, refer to the `ResultCode` (<a href="/errors/codes/105206">105206</a>, <a href="/errors/codes/105299">105299</a>) and `ResultMessage`.
    </ResponseField>
  </Accordion>
</AccordionGroup>

<ResponseExample>
  ```json 200 theme={null}
  {
      "Id": "cardreg_wt_11ed4694-d244-4bd1-92fb-dc473c99a9d4",
      "Tag": null,
      "CreationDate": 1726239226,
      "UserId": "user_m_01J7KACBPAV7XAF8AH9BDCJPRS",
      "AccessKey": "ehvrHoPE6FpjCCAgmNvg",
      "PreregistrationData": "lhOJ6CFiDJPCXViyHjfcayh92nouB3AAaB5yqiLCBT6yjkLPCptmxsUdfffAc6EE4uj9AuSfmwbdfKN3BMechzUU3Gz8ectEx70TDeupudr",
      "RegistrationData": null,
      "CardId": null,
      "CardType": "CB_VISA_MASTERCARD",
      "CardRegistrationURL": "https://pci.sandbox.mangopay.com/api/mangopay/vault/tokenize/eyJjbGllbnQiOiJhbnRob255aF90ZXN0MSIsInRva2VuIjoiUlBQTVdJR1hrd0ZJSGFacyJ9",
      "ResultCode": null,
      "ResultMessage": null,
      "Currency": "EUR",
      "Status": "CREATED"
  }
  ```
</ResponseExample>

<RequestExample>
  ```python cURL theme={null}
  curl -X POST https://api.sandbox.mangopay.com/v2.01/{ClientId}/cardregistrations \
    -H 'Content-Type: application/json' \
    -d '{
      "Tag": null,
      "UserId": "user_m_01J7KACBPAV7XAF8AH9BDCJPRS",
      "CardType": "CB_VISA_MASTERCARD",
      "Currency": "EUR"
  }  '
  ```

  ```json REST   theme={null}
  {
      "Tag": null,
      "UserId": "user_m_01J7KACBPAV7XAF8AH9BDCJPRS",
      "CardType": "CB_VISA_MASTERCARD",
      "Currency": "EUR"
  }  
  ```

  ```php PHP theme={null}
  <?php 

  require_once 'vendor/autoload.php';

  use MangoPay\MangoPayApi;
  use MangoPay\Libraries\ResponseException as MGPResponseException;
  use MangoPay\Libraries\Exception as MGPException;

  $api = new MangoPayApi();

  $api->Config->ClientId = 'your-client-id';
  $api->Config->ClientPassword = 'your-api-key';
  $api->Config->TemporaryFolder = 'tmp/';

  try {
      $cardRegistration = new \MangoPay\CardRegistration();

      $cardRegistration->UserId = '195627761';
      $cardRegistration->CardType = 'CB_VISA_MASTERCARD';
      $cardRegistration->Currency = 'EUR';
      $cardRegistration->Tag = 'Created using Mangopay PHP SDK';

      $response = $api->CardRegistrations->Create($cardRegistration);

      print_r($response);
  } catch(MGPResponseException $e) {
      print_r($e);
  } catch(MGPException $e) {
      print_r($e);
  }  
  ```

  ```javascript NodeJS   theme={null}
  const mangopayInstance = require('mangopay4-nodejs-sdk');
  const mangopay = new mangopayInstance({
      clientId: "your-client-id",
      clientApiKey: "your-api-key",
  })

  let user = {
      Id: 'user_m_01HQK25M6KVHKDV0S36JY9NRKR',
    }

  let userCardRegistration = {
      UserId: user.Id,
      Currency: 'EUR',
      CardType: 'CB_VISA_MASTERCARD'
  }

  const createCardRegistration = async(cardRegistration) => {
      return await mangopay.CardRegistrations.create(cardRegistration)
      .then((response) => {
          console.info(response)
          return response
      })
      .catch((err) => {
          console.log(err)
          return false
      })
  }

  createCardRegistration(userCardRegistration)  
  ```

  ```ruby Ruby   theme={null}
  require 'mangopay'

  MangoPay.configure do |client|
      client.preproduction = true
      client.client_id = 'your-client-id'
      client.client_apiKey = 'your-api-key'
      client.log_file = File.join(Dir.pwd, 'mangopay.log')
  end

  def createCardRegistration(params)
      begin
          response = MangoPay::CardRegistration.create(params)
          puts response
          return response
      rescue MangoPay::ResponseError => error
          puts "Failed : #{error.message}"
          puts "Error details: #{error.details}"
          return false
      end
  end

  params = {
      "UserId": "user_m_01J2BGH2PGWC4NNWGADT75ATB6",
      "CardType": "CB_VISA_MASTERCARD",
      "Currency": "EUR"
  }

  createCardRegistration(params)
  ```

  ```java Java  theme={null}
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.mangopay.MangoPayApi;
  import com.mangopay.core.enumerations.CardType;
  import com.mangopay.core.enumerations.CurrencyIso;
  import com.mangopay.entities.CardRegistration;

  public class CreateCardRegistration {
      public static void main(String[] args) throws Exception {
          MangoPayApi mangopay = new MangoPayApi();
      	  mangopay.getConfig().setClientId("your-client-id");
     	  mangopay.getConfig().setClientPassword("your-api-key");

          String userId = "user_m_01HT2NFK7Z2BRQNGNHMY30VVTT";
          CardRegistration cardReg = new CardRegistration();
          cardReg.setUserId(userId);
          cardReg.setCardType(CardType.CB_VISA_MASTERCARD);
          cardReg.setCurrency(CurrencyIso.EUR);
          cardReg.setTag("Created using the Mangopay Java SDK");

          CardRegistration createCardRegistration = mangopay.getCardRegistrationApi().create(cardReg);

          Gson prettyPrint = new GsonBuilder().setPrettyPrinting().create();
          String prettyJson = prettyPrint.toJson(createCardRegistration);

          System.out.println(prettyJson);
      }
  }
  ```

  ```python Python   theme={null}
  from pprint import pprint
  import mangopay

  mangopay.client_id='your-client-id'
  mangopay.apikey='your-api-key'

  from mangopay.api import APIRequest
  handler = APIRequest(sandbox=True)

  from mangopay.resources import NaturalUser, CardRegistration

  natural_user = NaturalUser.get('213600749')

  card_registration = CardRegistration(
      user_id = natural_user.id,
      currency = 'GBP',
      card_type =  'CB_VISA_MASTERCARD'
  )

  create_card_registration = card_registration.save()

  pprint(create_card_registration)  
  ```

  ```csharp .NET  theme={null}
  using MangoPay.SDK;
  using MangoPay.SDK.Core.Enumerations;
  using MangoPay.SDK.Entities.POST;
  using Newtonsoft.Json;

  class Program
  {
      static async Task Main(string[] args)
      {
          MangoPayApi api = new MangoPayApi();

          api.Config.ClientId = "your-client-id";
          api.Config.ClientPassword = "your-api-key";

          var userId = "user_m_01J2TZ261WZNDM0ZDRWGDYA4GN";

          var cardRegistration = new CardRegistrationPostDTO(
              userId, 
              CurrencyIso.EUR,
              CardType.CB_VISA_MASTERCARD
          );

          var createCardRegistration = await api.CardRegistrations.CreateAsync(cardRegistration);

          string prettyPrint = JsonConvert.SerializeObject(createCardRegistration, Formatting.Indented);
          Console.WriteLine(prettyPrint);
      }
  }
  ```
</RequestExample>
