Opayo merchant session key. Authentication values are missing

796 Views Asked by At

We are getting the following error when executing this:

[description] => Authentication values are missing [code] => 1001

Can anyone see what I am doing wrong. I tried removing the base64_encode function but this didn't have any impact.

I got the integration key and password from opayo (sagepay) - the test environment.

My php code follows:

$key = base64_encode("My Integration Key");
$password = "My Integration Password";

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://pi-test.sagepay.com/api/v1/merchant-session-keys",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => '{ "vendorName": "MY VENDOR" }',
    CURLOPT_HTTPHEADER => array(
        "Authorization: Basic $key:$password",
        "Cache-Control: no-cache",
        "Content-Type: application/json"
    )
));

$response = curl_exec($curl);
$response = json_decode($response, true);
$err = curl_error($curl);

curl_close($curl);

Tia for any help

2

There are 2 best solutions below

0
jagku On

Both the key and password had to be base 64 encoded.

ie $key = base64_encode("My Integration Key:My Integration Password"); and then fed in to the curl http header as

"Authorization: Basic $key",

0
Joe Ratzer On

I had the same issue, so created a NuGet package for this API-client code: https://github.com/joeratzer/opayo-admin-and-reporting-api-client.

You can find the NuGet package here:

https://www.nuget.org/packages/Joe.Opayo.Admin.Api.Client/1.1.0

The client app allows code like this:

var client = new OpayoAdminApiClient();
var isTest = true;
var request = new OpayoApiRequest(ApiCommandType.GetTransactionDetail, "password", isTest, "user-name", "vendor-name");
var commandSpecificXml = "<vendortxcode>01Jan2010Transaction12345</vendortxcode>"; 
return await client.ProcessApiCommandAsync<TransactionDetail>(request, commandSpecificXml);