Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions api
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

// Your AWS Access Key ID, as taken from the AWS Your Account page
$aws_access_key_id = "<your Key>";

// Your AWS Secret Key corresponding to the above ID, as taken from the AWS Your Account page
$aws_secret_key = "<your_secret_key>";

// The region you are interested in

$endpoint = "webservices.amazon.in";

$uri = "/onca/xml";

$params = array(
"Service" => "AWSECommerceService",
"Operation" => "ItemLookup",
"AWSAccessKeyId" => "AKIAIQF4GHHSIUR76U6Q",
"AssociateTag" => "<your tag>",
"ItemId" => " B01MSTDS3N,B01LTI1JEM,",
"IdType" => "ASIN",
"ResponseGroup" => "Offers",
"Condition" => "All"
);

// Set current timestamp if not set
if (!isset($params["Timestamp"])) {
$params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
}

// Sort the parameters by key
ksort($params);

$pairs = array();

foreach ($params as $key => $value) {
array_push($pairs, rawurlencode($key)."=".rawurlencode($value));
}

// Generate the canonical query
$canonical_query_string = join("&", $pairs);

// Generate the string to be signed
$string_to_sign = "GET\n".$endpoint."\n".$uri."\n".$canonical_query_string;

// Generate the signature required by the Product Advertising API
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $aws_secret_key, true));

// Generate the signed URL
$request_url = 'http://'.$endpoint.$uri.'?'.$canonical_query_string.'&Signature='.rawurlencode($signature);

// echo "Signed URL: \"".$request_url."\"";


$xml=simplexml_load_file($request_url) or die("Error: Cannot create object");

echo $xml->Items->Item[0]->OfferSummary->LowestNewPrice->Amount;
echo "</br>";
echo $xml->Items->Item[1]->OfferSummary->LowestNewPrice->Amount;

?>