I am attempting to use the Amazon MWS GetMatchingProductForId API, and I am stuck on trying to get information for multiple isbn's. The format needs to be in the form of: IdList.Id.1=isbn[x], where isbn[x] would be my array. I need to be able to list them in a list of 20 (ie. IdList.Id.1=, IdList.Id.2= ...IdList.Id.20= ). I thought I could use implode($isbn) like this:
$count=0;
function ProductId_xml($searchTerm) {
$params = array(
'AWSAccessKeyId' => AWS_ACCESS_KEY_ID,
'Action' => "GetMatchingProductForId",
'SellerId' => MERCHANT_ID,
'SignatureMethod' => "HmacSHA256",
'SignatureVersion' => "2",
'Timestamp'=> gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time()),
'Version'=> "2011-10-01",
'MarketplaceId' => MARKETPLACE_ID,
'IdType' => "ISBN",
);
$id=array(explode(',',$searchTerm));
foreach ($id as $newId)
{
$count .= $count +1;
$params += array('IdList.Id.'.$count => $newId);
} //end of foreach
// 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("&", $url_parts);
$string_to_sign = "GET\nmws.amazonservices.com\n/Products/2011-10-01\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 = "https://mws.amazonservices.com/Products/2011-10-01" . '?' . $url_string . "&Signature=" . $signature;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
$parsed_xml = simplexml_load_string($response);
return ($parsed_xml);
}
}
?>
$searchterm is my array of isbn numbers, but that only lists them as a string of isbn's. I know that this works if I only use one isbn at a time, but I need to run them in batches of 20 to speed up my process. I am not sure where to go from here. Any help would be greatly appreciated. EDIT: I have updated the function so that it will include the batch of 20 isbn's in $params, but I am not sure that the way I added it is correct.