Error 401 Unauthorized

You are here

1 post / 0 new
Error 401 Unauthorized

Attempting to process a transaction and receive an error 401 (Unauthorized). You may also see further down the log:

  • "Error response, or unable to parse response."
  • "The actual request data did not match the expected request data."

The API is expecting the data in the authKey to match the data in the JavaScript initialize. There may be other items in the initialize script, but you must include what is in the authKey as well.

Example below there is a postbackUrl in the payload, but not in the initialize script, this transaction will end with "401 Unauthorized":

Payload included in the authKey

$req = [
        "merchantId" => $merchant['ID'],
        "merchantKey" => $merchant['KEY'], 
        "requestType" => $requestType,
        "requestId" => $requestId,
        "amount" => $request['amount'],
        "nonce" => $nonces['salt'],
        "postbackUrl" => $request['postbackUrl'], 
        "environment" => $request['environment'], 
        "preAuth" => $request['preAuth'] 

JavaScript initialize

        apiKey: "<?php echo $developer['ID']; ?>", 
        merchantId: "<?php echo $merchant['ID']; ?>", 
        authKey: "<?php echo $authKey; ?>", 
        requestType: "<?php echo $requestType; ?>", 
        requestId: "<?php echo $requestId; ?>", 
        amount: "1.00", 
        elementId: "paymentButton", 
        nonce: "<?php echo $nonces['salt']; ?>", 
        debug: true, 
        addFakeData: true, 
        preAuth: false, 
        environment: "<?php echo $request['environment']; ?>", 
        billing: {
            name: "John Simpson",
            street: "123 Main St",
            city: "Savannah",
            zip: "31405"