title: MPGS (mastercard): How to tokenize a transaction (how to create token)?
body: <p>I'm trying to create token with MPGS.</p>
  
  <p>I'm following this guide:</p>
  
  <p>https://<strong>sample-sub.domain</strong>.mastercard.com/api/documentation/integrationGuidelines/supportedFeatures/pickAdditionalFunctionality/tokenization/tokenization.html?locale=en_US#x_tokenConfiguration</p>
  
  <p>In the section "Token Operations" > "Tokenize", it says:</p>
  
  <blockquote>
    <p>You can use this operation to <strong>create</strong> or update a <strong>token</strong> by storing
    payment details against the token. ...</p>
  </blockquote>
  
  <p>I'm posting this to help people who are frustrating like me with MPGS. I faced series of issues, and pulled my hair off many times. So here's the issues I faced and how to solve them (I'm stuck with issue #4). </p>
  
  <hr>
  
  <p><strong>Issue #1:</strong> Invalid credentials.</p>
  
  <p><strong>Fix</strong>: Make sure you're hitting the correct URL. </p>
  
  <p>https://<strong>example-subdomain</strong>.mastercard.com/..</p>
  
  <p>https://<strong>some.other-example</strong>.mastercard.com/..</p>
  
  <p>https://<strong>MILLION-OTHER-POSSIBILITIES</strong>.mastercard.com/..</p>
  
  <p>Even the documentation guide link have these same sub-domains, so make sure you're hitting the correct URL, and make sure you're following the correct documentation link.</p>
  
  <hr>
  
  <p><strong>Issue #2:</strong> Invalid parameters, or server asking for parameters although you've provided them.</p>
  
  <p><strong>Fix:</strong> If using Postman, make sure you set the parameters in "Body" > "<strong>raw</strong>" as JSON, like so:</p>
  
  <pre><code>{
      "sourceOfFunds": {
          "provided": {
              "card": {
                  "expiry": {
                      "month": "05",
                      "year": "21"
                  },
                  "number": "5123456789012346"
              }
          },
          "type": "CARD"
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Issue #3:</strong> Authorization required</p>
  
  <p><strong>Fix:</strong> If using Postman, click on "Authorization", set "Type" it to <strong>Basic Auth</strong>, for "Username" set it to <strong>merchant.YOUR_MERCHANT_ID</strong>, for "Password" set it to <strong>YOUR_API_PASSWORD</strong></p>
  
  <hr>
  
  <p><strong>Issue #4 (stuck here):</strong> Value '9999999999999999' is invalid. Card token must not be supplied</p>
  
  <p>Method: <strong>PUT</strong></p>
  
  <p>URL: https://<strong>test-my.sample.gateway</strong>.mastercard.com/api/rest/version/46/merchant/<strong>MY_MERCHANT_ID</strong>/token/9999999999999999</p>
  
  <p>Authorization: set correctly in Authorization tab</p>
  
  <p>Body > raw:</p>
  
  <pre><code>{
      "sourceOfFunds": {
          "provided": {
              "card": {
                  "expiry": {
                      "month": "05",
                      "year": "21"
                  },
                  "number": "5123456789012346"
              }
          },
          "type": "CARD"
      }
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>{
      "error": {
          "cause": "INVALID_REQUEST",
          "explanation": "Value '9999999999999999' is invalid. Card token must not be supplied",
          "field": "tokenid",
          "validationType": "INVALID"
      },
      "result": "ERROR"
  }
  </code></pre>
  
  <p><strong>Q:</strong> Not sure what to do to tokenize the transaction..?! I'm stuck with <strong>issue #4</strong>.</p>