# Transfer M4M Tokens to SCOF
source: https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/m4m_migration/step2/index.md

## Step 2: Transfer M4M Tokens to SCOF {#step-2-transfer-m4m-tokens-to-scof}

Similar to a Token Unique Reference (TUR) and on M4M (MDES for Merchant), Secure Card on File (SCOF) needs `srcDigitalCardId` to make API calls. This `srcDigitalCardId` is created as part of tokenization in SCOF.
Warning: The migration does not re-tokenize your existing tokens, and you must use SCOF APIs to create and migrate new identifiers in SCOF.

You can migrate M4M tokens to SCOF in one of two ways:

1. Calling the [Enroll Card API](https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/m4m_migration/step2/index.md#for-integrators-utilizing-the-enroll-api) to migrate one TUR in a single request.
2. Calling the [Batch Enroll API](https://developer.mastercard.com/mastercard-checkout-solutions/tutorial/m4m_migration/step2/index.md#for-integrators-utilizing-the-batch-enroll-api) to migrate 250 TURs in a single request.

## For Integrators utilizing the Enroll API {#for-integrators-utilizing-the-enroll-api}

Single card enrollment is recommended for Integrators looking to migrate a smaller volume of TURs onto Secure Card on File (for example: less than or equal to 20 million active tokens).

You can use the Enroll Card API request by following the steps outlined below:

1. Provide each TUR in the [Enroll Card](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/api-reference/apis/index.md#card) request by populating:

   * `enrolmentReferenceId` with the existing M4M TUR
   * `enrolmentReferenceType` as `EXISTING_TOKEN_UNIQUE_REFERENCE`   

     ```javascript

     {
       "serviceId": "SECURE_COF_MERCHANT_OBO#START_SANDBOX_SRCI-KAUSHAL_TAILOR#01",
       "srcDpaId": "b756a2b0-ef62-4c62-a6de-f72e75ce5f17",
       "enrolmentReferenceData": {
         "enrolmentReferenceId": "DM4MMC0000144136fb04571884c24d7388daa18a772b05e5",
         "enrolmentReferenceType": "EXISTING_TOKEN_UNIQUE_REFERENCE"
       }
     }
     ```

2. On successful enrollment, SCOF provides a `srcDigitalCardId` that you can use for future Checkouts.   


   ```javascript
   {
      "srcCorrelationId": "b6db0d1c-5afa-46a0-b336-47ca05da15a6",
      "maskedCard": {
         "srcDigitalCardId": "fb921d5c-89cd-44d3-90f6-3d465e277791",
         "panBin": "222269",
         "panLastFour": "4574",
         "tokenUniqueReference": "DM4MMC0000144136fb04571884c24d7388daa18a772b05e5",
         "tokenLastFour": "0728",
         "digitalCardData": {
           "status": "ACTIVE",
           "descriptorName": "MasterCard Test Bank",
           "artUri": "https://sbx.assets.mastercard.com/card-art/combined-image-asset/6713d73d-a701-4bd2-bc9b-2e98940de9c7.png",
           "isCoBranded": "false",
           "issuerName": "Test IssuerÂ",
           "longDescription": "Test Bank for MasterCard MTF",
           "foregroundColor": "0f0f0f"
          },
       "panExpirationMonth": "12",
       "panExpirationYear": "2024",
       "paymentCardDescriptor": "mastercard",
       "paymentCardType": "CREDIT",
       "serviceId": "SECURE_COF_MERCHANT_OBO#START_SANDBOX_SRCI-KAUSHAL_TAILOR#01",
       "dateOfCardCreated": "2023-05-31T20:23:47.005Z",
       "maskedConsumer": {
           "srcConsumerId": "4ba06d41-0c59-41f5-adc1-b62b9ab6e74d",
           "maskedConsumerIdentity": {
               "identityType": "EXTERNAL_ACCOUNT_ID",
               "maskedIdentityValue": "SYSTEM_GENERATED_ccb5ef5d-c109-412f-8aa3-27b24080c14d"
           },
           "complianceSettings": {
               "privacy": null,
               "tnc": null
           },
           "status": "ACTIVE",
           "dateConsumerAdded": "2023-05-31T20:23:46.344Z"
       }
     }
   }
   ```

   <br />

3. Maintain the status of migrated tokens and map the TURs/tokens to `srcDigitalCardId` to ensure all tokens are eventually migrated.

Note: Transaction per Second (TPS) will be throttled in the single-card enrollment use case at 5 TPS.

## For Integrators utilizing the Batch Enroll API {#for-integrators-utilizing-the-batch-enroll-api}

[Batch Enrollment](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/card-on-file/create-tokens/tokenization-of-existing-cards/index.md) is recommended for Integrators looking to migrate a larger volume of TURs onto Secure Card on File (for example: more than or equal to 20 million active tokens).
Note: These TURs will be migrated asynchronously offline, and you will receive a new Batch Enrollment Notification (on a per-card basis) as each TUR is processed. Listen for these notifications, as newly migrated TURs can be used immediately upon receipt of the notification. For detailed instructions on completing this flow, refer to the [Batch Enrollment Notification](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/card-on-file/create-tokens/tokenization-of-existing-cards/index.md) section.

You can use the [Batch Enroll API](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/api-reference/apis/index.md#cards-batch-enrollment) by following the steps outlined below:

1. Submit a Batch request (with up to 250 existing TURs) containing the existing TUR in the `EnrollmentReferenceId` parameter, and a unique `externalEnrollmentReferenceId` for each TUR.

   ```javascript

   { 

     "srcClientId": "eccbf087-f159-4d69-b31d-00bec75c0474",
     "serviceId": "SECURE_COF_COMMERCE_PLATFORM#Mastercard#01",
     "srcDpaId": "b756a2b0-ef62-4c62-a6de-f72e75ce5f17",
     "externalBatchId": "9d56d47e-70d6-470f-a0a6-c0fccb7e3a43",
     "enrollmentData": [
       {
         "enrollmentSource": [
           {
             "externalEnrollmentReferenceId": "ebcaf087-f159-4d69-b31d-00bec75c0864",
             "enrollmentReferenceType": "EXISTING_TOKEN_UNIQUE_REFERENCE",
             "enrollmentReferenceId": "DM4MMC0000144136fb04571884c24d7388daa18a772b05e5"
           }
         ]
       },
       {
         "enrollmentSource": [
           {
             "externalEnrollmentReferenceId": "ebcaf087-f159-4d69-b31d-00bec75c0868",
             "enrollmentReferenceType": "EXISTING_TOKEN_UNIQUE_REFERENCE",
             "enrollmentReferenceId": "DM4MMC0000144136fb04571884c24d7388daa18a772b05e4"
           }
         ]
       },
       {
         "enrollmentSource": [
           {
             "externalEnrollmentReferenceId": "ebcaf087-f159-4d69-b31d-00bec75c0868",
             "enrollmentReferenceType": "EXISTING_TOKEN_UNIQUE_REFERENCE",
             "enrollmentReferenceId": "DM4MMC0000144136fb04571884c24d7388daa18a772b05e4"
           }
         ]
       }
     ]
   } 
   ```

   <br />

2. Receive an acknowledgement response from Mastercard Checkout Solutions. The response will contain a `batchId`, which is a unique identifier generated by Mastercard Checkout Solutions created per batch request and shared with the Issuer. Use the `batchID` to get the status of the batch process later.  


   ```javascript

   {
     "batchId": "dccbf087-f159-4d69-b31d-00bec75c0970",
     "externalBatchId": "6ecbf087-f159-4d69-b31d-00bec75c0478"
   }
   ```

   <br />

3. Mastercard Checkout Solutions adds the batch request to the Batch Processing queue.

4. Batch Processing queue processes the TURs asynchronously offline.

5. Receive a Batch Enrollment Notification (per-card) containing a `srcDigitalCardId` and associated card metadata for successful enrollments, or an error for unsuccessful enrollments.

Note:   

* To prevent cross-batch mapping errors, always check `batchId` first upon receiving a per-card enrollment notification. Then, use `externalEnrollmentReferenceId` to map `srcDigitalCardId` (or errors) correctly.
* Use the `srcDigitalCardId` in Checkout API to fetch the token and cryptogram when a transaction is occurring.
* For any missed Batch Migration Notifications, utilize the [getBatch API](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/api-reference/apis/index.md#cards-batch-enrollment) to retrieve the status of the TUR. After calling the getBatch API, you will receive a successful migration response with the `cardId` or an unsuccessful response with an error message. Refer to the [Batch Notification Status](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/card-on-file/create-tokens/tokenization-of-existing-cards/index.md#receiving-bulk-enrollment-notifications) for step-by-step instructions on how to retrieve the status of bulk migration.

## Key Considerations {#key-considerations}

* Until all tokens are successfully migrated, you must maintain two integrations (M4M and SCOF) to support lifecycle management updates from both MDES and Mastercard Checkout Solutions.

* Migrating tokens from M4M to SCOF will not result in the creation of a new token. SCOF creates new `srcDigitalCardId` that need to be used for subsequent API calls in SCOF.

* For each TRID you migrate, we recommend a TUR migration before the first FPAN based tokenization to ensure that the Integrator has mapped the new `serviceId` to the expected TRID/Token correctly, but it is not mandatory.

* During the process of migration, you can enroll all net-new cards in SCOF using [PAN](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/card-on-file/create-tokens/index.md) and [push account receipt](https://developer.mastercard.com/mastercard-checkout-solutions/documentation/use-cases/card-on-file/create-tokens/scof-push-acc-receipt/index.md). It is not recommended to enroll new cards via M4M and then immediately migrate to SCOF; this is a redundant process that will add latency and is inconsistent with best practices.

* Migration of tokens from M4M to SCOF should happen offline (when the consumer is not present) and throttled at Transaction per Second (TPS) agreed with Mastercard.

* Trying to migrate an invalid credential will give a **INVALID_STATE** (HTTP 400 Bad Request) error. Delete this credential and refrain from migrating this credential.

* After successfully transferring an M4M token to SCOF, if you make further requests to MDES APIs, MDES may respond with **AUTHORIZATION_FAILED** error.

