Amazon offer a scratchpad for the advertising API with code in PHP and curl. Unfortunately the PHP code uses fopen - which is no good on my hosting server, where remote url open is off.
I've got this far, with the fopen section commented out (that worked on my home server, so I know $headers array is fine! $payload is jSON
The error I get is "Curl error: 500 The request processing has failed due to some unknown error, exception or failure. Please retry again."
$headers = $awsv4->getHeaders ();
$payload="{"
." \"Keywords\": \"".stripslashes($_POST['book'])."\","
." \"Resources\": ["
." \"CustomerReviews.StarRating\","
." \"Images.Primary.Large\","
." \"Images.Primary.Small\","
." \"ItemInfo.ByLineInfo\","
." \"ItemInfo.ContentInfo\","
." \"ItemInfo.Classifications\","
." \"ItemInfo.ExternalIds\","
." \"ItemInfo.Features\","
." \"ItemInfo.ProductInfo\","
." \"ItemInfo.TechnicalInfo\","
." \"ItemInfo.Title\","
." \"Offers.Listings.Price\""
." ],"
." \"PartnerTag\": \"keepchickens-21\","
." \"PartnerType\": \"Associates\","
." \"Marketplace\": \"www.amazon.co.uk\""
."}";
$headerString = "";
foreach ( $headers as $key => $value ) {
$headerString .= $key . ': ' . $value . "\r\n";
}
$params = array (
'http' => array (
'header' => $headerString,
'method' => 'POST',
'content' => $payload
)
);
$stream = stream_context_create ( $params );
/*
$fp = @fopen ( 'https://'.$host.$uriPath, 'rb', false, $stream );
if (! $fp) {
throw new Exception ( "Exception Occured" );
}
$response = @stream_get_contents ( $fp );
if ($response === false) {
throw new Exception('<p>Nothing found</p>');
}
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://'.$host.$uriPath);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$response=curl_exec($ch);
echo 'Curl error: ' . curl_error($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($response);
$data=json_decode($response);
Any ideas what is wrong please?