PHP - Search for item by UPC code in Itemmaster.com

303 Views Asked by At

This is the api: https://api.itemmaster.com/v2/api but I don't know write the curl code to get the item with UPC: 00040000006039 Where I have to add username and password ?

2

There are 2 best solutions below

0
On BEST ANSWER

CURL with along with username and password and set as HTTP Header parameters as per API Documentation.

change you credentials below for XXXX

$url ='https://api.itemmaster.com/v2/item/?upc=00040000006039'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($ch,CURLOPT_HTTPHEADER,array('username: XXXXX','password: XXXX'));
// OR
// curl_setopt($ch,CURLOPT_HTTPHEADER,array('username: XXXXX'));
// curl_setopt($ch,CURLOPT_HTTPHEADER,array('password: XXXX'));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
2
On

I would suggest using Guzzle: http://guzzle.readthedocs.org/en/latest/

The code looks something like this:

$client = new Client([
    // Base URI is used with relative requests
    'base_uri' => 'https://api.itemmaster.com/v2/',
    // Set username and password in the header here
    'headers' => ['username' => 'user_name', 'password' => 'thePassword']
]);
$response = $client->get('item',
    [
    'query' => ['idx' => '0','upc' => '00040000006039']
    ]);