getting 403 Forbidden Error when creating creates a shopper entity on Bluesnaps using the API

526 Views Asked by At

I am trying to creates a shopper entity on Bluesnaps using its API but I am unable to do that.

here is the URL: http://shimion.com/create-shopper.php?firstName=bob&lastName=Smith&[email protected]&address1=123%20Main%20Street&address2=Apt%20K-9&city=Parkville&state=TN&country=us&phone=411-555-1212&zipcode=37027

Here is the CODE:

 function get_shopper_from_header($ch, $string) {
$firstName = htmlspecialchars($_REQUEST['firstName']);           
$lastName  = htmlspecialchars($_REQUEST['lastName']);             
$email     = htmlspecialchars($_REQUEST['email']);     
$address1  = htmlspecialchars($_REQUEST['address1']);
$address2  = htmlspecialchars($_REQUEST['address2']);
$city      = htmlspecialchars($_REQUEST['city']);
$state     = htmlspecialchars($_REQUEST['state']);
$country   = htmlspecialchars($_REQUEST['country']);
$zipCode   = htmlspecialchars($_REQUEST['zipcode']);
$phone     = htmlspecialchars($_REQUEST['phone']);
$credentials = $username.':'.$password;
$firstName = 'Bob';
$lastName = 'Smith';
$email = "[email protected]";
$address1 = "123 Main Street";
$address2 = "Apt K-9";
$city = "Parkville";
$state = "TN";
$country = "us";
$zipCode = "37027";
$phone = "411-555-1212";
$xmlToSend = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<shopper xmlns=\"http://ws.plimus.com\">
<shopper-info>
<shopper-contact-info>
<first-name>". $firstName ."</first-name>
<last-name>". $lastName ."</last-name>
<email>". $email ."</email>
<address1>". $address1 ."</address1>
<city>". $city ."</city>
<zip>". $zipCode ."</zip>
<country>". $country ."</country>
<state>". $state ."</state>
<phone>". $phone ."</phone>
</shopper-contact-info>
<locale>en</locale>
</shopper-info>
<web-info>
<ip>62.219.121.253</ip>
<remote-host>bzq-219-121-253.static.bezeqint.net.reinventhosting.com</remote-host>
<user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3; .NET CLR 2.0.50727</user-agent>
<accept-language>en-us</accept-language>
</web-info>
</shopper>";
$service = 'https://sandbox.plimus.com/services/2/shoppers';
$contentType = array('Content-type: application/xml');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend);
curl_setopt($ch, CURLOPT_HTTPHEADER, $contentType);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'get_shopper_from_header');
$response = curl_exec($ch);
if ( curl_errno($ch) ) {
echo 'HTTP error code: ' . curl_errno($ch) . '<br>error-message: "' . curl_error($ch) . '"';
return;
}
if (is_numeric($shopper_id)) {
echo '<br>
A new shopper entity was created on our servers with shopper-id: '
. $shopper_id .
'<br><br>';
}
else {
echo '<br><br>
<font color="red"><b>Something went wrong!</b></font>
<br>
Server reponse:
<br><br>
<pre style="display: block; font-family: monospace; white-space: pre; margin: 1em 0px;">'
. $response .
'</pre><br>';
}
?>
1

There are 1 best solutions below

0
On

If you are using a it from localhost than it wont work, you will need ssl also, openssl for localhost.
if you are using it from live you need to add ip address as your server ip address and you have you have to add that ip address in your bluesnap account too in general settings.