How to get product data using api.ssactivewear.com in php?

476 views Asked by At

By using api.ssactivewear.com, there is no option for php code in example (https://api.ssactivewear.com/V2/Help_Examples.aspx). Any help or support may solve my issue. I have done below mention code in php to get data in xml:

ini_set("allow_url_fopen", 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.ssactivewear.com/v2/products/B00760003?username=xxxxx&api_key=xxxxxxxxxxxxxxxxxx');
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);

I got below mention result :- string(68)

"{ "message": "Authorization has been denied for this request." }"

2

There are 2 answers

0
Dev On BEST ANSWER

Got the solution and it works for me:

$username = "xxxxx";
$password = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$remote_url = 'https://api.ssactivewear.com/v2/categories/';

// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header' => "Authorization: Basic " . base64_encode("$username:$password")            
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above

$json = file_get_contents($remote_url, false, $context);

$json=str_replace('},
]',"}
]",$json);

$data = json_decode($json, true);

var_dump($data);
0
Radhanatha Mohapatra On

I have to find a solution. All below codes are working for me.

$apiPath =  "https://api.ssactivewear.com/v2/products";
$username = 'XXXXXXXX';
$password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$apiPath);
$headers = array(
    'Content-Type:text/html'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);