What if I get 401 error code (Access denied due to unauthorized transaction, please check client key or server key)?

'401' error code means 'Access denied due to unauthorized transaction, please check client key or server key', and here's what might happen to you:

  • You are using Access Keys Production (Client Key & Server Key), but you are using Sandbox endpoint URL,
  • You are using Access Keys Sandbox (Client Key & Server Key), but you are using Production endpoint URL,
  • Your Server Key is not converted yet to base64,
  • You have space when converting.

If you get this error, please check your access keys. Below are the steps to find your access keys:

  1. Log in to your Midtrans portal,
  2. Click Settings menu,
  3. Click Access Keys sub-menu,
  4. You will see your Merchant ID, Server Key, and Client Key