title: How to check the stock of amazon product using its Amazon Product Advertising API in php?
body: <p>Does anyone know that how to check the stock of amazon product from Amazon Product Advertising API??</p>
  
  <p>Plz dont share links of API docs.. just tell me the way..</p>
  
  <p>i have used the follwing code to display the results for some specific product.
  Guide me that how can i see the stock of searched product?</p>
  
  <pre><code>&lt;?php 
  
  define('AWS_ACCESS_KEY_ID', 'my-access-key'); 
  
  define('AWS_SECRET_ACCESS_KEY', 'my-secret-key'); 
  
  define('AMAZON_ASSOC_TAG', 'my-associate-tag'); 
  
  
  function amazon_get_signed_url($searchTerm) 
  
  { 
  
  $base_url = "http://ecs.amazonaws.com/onca/xml"; 
  
  $params = array( 'AWSAccessKeyId' =&gt; AWS_ACCESS_KEY_ID, 'AssociateTag' =&gt; AMAZON_ASSOC_TAG, 'Version' =&gt; "2010-11-01", 'Operation' =&gt; "ItemLookup", 'Service' =&gt; "AWSECommerceService",  'ResponseGroup' =&gt; "ItemAttributes", 'ItemId'=&gt; $searchTerm);
  
  if(empty($params['AssociateTag'])) 
  { 
   unset($params['AssociateTag']); 
  } 
  
  // Add the Timestamp 
  
  $params['Timestamp'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()); 
  
  // Sort the URL parameters 
  $url_parts = array(); 
  foreach(array_keys($params) as $key) 
  $url_parts[] = $key . "=" . str_replace('%7E', '~', rawurlencode($params[$key])); 
  sort($url_parts); 
  // Construct the string to sign 
  $url_string = implode("&amp;", $url_parts); 
  $string_to_sign = "GET\necs.amazonaws.com\n/onca/xml\n" . $url_string; 
  // Sign the request 
  $signature = hash_hmac("sha256", $string_to_sign, AWS_SECRET_ACCESS_KEY, TRUE);
   // Base64 encode the signature and make it URL safe 
   $signature = urlencode(base64_encode($signature)); 
   $url = $base_url . '?' . $url_string . "&amp;Signature=" . $signature; 
   return ($url); 
  }
  
  $getthis = 'B004XIE6WI'; /*---- Product ASIN-----*/
  $show = amazon_get_signed_url($getthis);
  
  $ch = curl_init($show); 
  curl_setopt($ch, CURLOPT_HEADER, false); 
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
  $c = curl_exec($ch); 
  $xml = simplexml_load_string($c);
  $json = json_encode($xml); 
  $array = json_decode($json,TRUE);
  
  echo "&lt;pre&gt;";
  print_r($array);
  echo "&lt;/pre&gt;";
  
  ?&gt;
  </code></pre>