1

Receiving 401 Authentication Access error when trying to request Hosted Payment Field access token via PHP. I have followed this tutorial -> Easy start with BlueSnap hosted payment fields; read about these similar issues -> 1. BlueSnap integration with node js and angular 2. Error getting payment_field_token in Bluesnap API as well as read through the basic auth info http://developers.bluesnap.com/docs/authentication with no luck. Can anyone figure this out?

<?php
$TokenRequest=curl_init();
curl_setopt($TokenRequest, CURLOPT_URL, "https://sandbox.bluesnap.com/services/2/payment-fields-tokens");
curl_setopt($TokenRequest, CURLOPT_HEADER, 1);
curl_setopt($TokenRequest, CURLOPT_HTTPHEADER, array("Authorization: Basic CREDENTIALS_HERE", "Content-type: application/json"));
curl_setopt($TokenRequest, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($TokenRequest, CURLOPT_RETURNTRANSFER, true);
$TokenResponse=curl_exec($TokenRequest);
list($Headers, $Response)=explode("\r\n\r\n", $TokenResponse, 2);
$Headers=explode("\n", $Headers);
foreach($Headers as $Header)
{
if (stripos($Header, "Location")!==false)
{
$Token=trim(str_replace("Location: ", "", $Header));
}
}
?>

2 Answers2

0

I work for BlueSnap.

A 401 error usually means a permission issue. Did you white list your IP in the BlueSnap console. Docs on how to do that can be found here: https://developers.bluesnap.com/docs/api-credentials . If you can provide me the actual JSON object (or XML) you are sending I can try to trace the exact error and try to determine root cause.

I found your API calls and you are doing a GET instead of a POST. The create a token you need to call a POST.

  • Yes my public IP and server ip are whitelisted. Also connecting through SSL on my domain. This is what is being returned. HTTP Status 401 – Unauthorized Type Status Report Message Full authentication is required to access this resource Description The request has not been applied because it lacks valid authentication credentials for the target resource. Apache Tomcat Version X. I'm not sure what you mean by providing the object I'm sending? The base64 encoded authorization? If so then you contact me through the BlueSnap Zendesk @ Sandbox Merchant ID #571981 and I'll responde promptly. – EXECUTOR brandon May 04 '18 at 15:43
0

In the following URL you will find how to create the credentials to be able to generate the token: https://developers.bluesnap.com/docs/api-credentials

once you have the username and password, substitute the data of the variables: $username, $password:

the following code works for me

$host = 'https://sandbox.bluesnap.com/services/2/payment-fields-tokens';
$username = 'API_1644786117605226907536';
$password = '654321Pm!';


$TokenRequest=curl_init();
curl_setopt($TokenRequest, CURLOPT_URL, $host);
curl_setopt($TokenRequest, CURLOPT_HEADER, 1);
curl_setopt($TokenRequest, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($TokenRequest, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($TokenRequest, CURLOPT_RETURNTRANSFER, true);
$TokenResponse=curl_exec($TokenRequest);
list($Headers, $Response)=explode("\r\n\r\n", $TokenResponse, 2);
$Headers=explode("\n", $Headers);
foreach($Headers as $Header)
{
if (stripos($Header, "Location")!==false)
{
$Token=trim(str_replace("Location: ", "", $Header));
}
}
print_r($Token);

$HOSTEDFIELDTOKENID = str_replace("https://sandbox.bluesnap.com/services/2/payment-fields-tokens/", "", $Token);
echo '<br><br><br><br>';
print_r($HOSTEDFIELDTOKENID);