I'm trying to replicate the following HTTP request made by Amazon's UI tool to access their Marketplace Web Services (MWS API)
This is the request made when using their UI tool. Note, the HTTP request info was taken from Google Chrome's developer console.
General
Request URL:https://mws.amazonservices.com/Products/2011-10-01
Request Method: POST
Status Code:200 OK
Remote Address:54.239.24.6:443
Referrer Policy:no-referrer-when-downgrade
Request Headers
POST /Products/2011-10-01 HTTP/1.1
Host: mws.amazonservices.com
Connection: keep-alive
Content-Length: 309
Origin: https://mws.amazonservices.com
x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: text/plain, /
X-Requested-With: XMLHttpRequest
Referer: https://mws.amazonservices.com/scratchpad/index.html
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: csm-hit=20.82|1494090798243
Form Data
AWSAccessKeyId: {{API KEY}}
Action:GetMatchingProductForId
SellerId: {{API KEY}}
SignatureVersion:2
Timestamp:2017-05-06T17:43:36Z
Version:2011-10-01
Signature:wVax9gw0DfIfeL7s4Z2IZynwwryi0c6tIkfE7IQY1RI=
SignatureMethod:HmacSHA256
MarketplaceId:ATVPDKIKX0DER
IdType:UPC
IdList.Id.1:034264456730
This is my PHP script using GuzzleHTTP library to try and emulate the request.
<?php
require './vendor/autoload.php';
use GuzzleHttp\Client;
$body = 'AWSAccessKeyId=AKIAJFTQQL6UN7RO6WBQ&Action=GetMatchingProductForId&SellerId=AWWNSYIT4NM3&SignatureVersion=2&Timestamp=2017-05-06T17%3A43%3A36Z&Version=2011-10-01&Signature=wVax9gw0DfIfeL7s4Z2IZynwwryi0c6tIkfE7IQY1RI%3D&SignatureMethod=HmacSHA256&MarketplaceId=ATVPDKIKX0DER&IdType=UPC&IdList.Id.1=034264456730';
$jar = new \GuzzleHttp\Cookie\CookieJar();
$client = new Client([
'base_uri'=>'https://mws.amazonservices.com',
'cookies'=>$jar,
'headers'=>[
'User-Agent'=>'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36',
'Host'=> 'mws.amazonservices.com',
'Connection'=>'keep-alive',
'Content-Length'=>'309',
'Origin'=>'https://mws.amazonservices.com',
'x-amazon-user-agent'=>'AmazonJavascriptScratchpad/1.0 (Language=Javascript)',
'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
'Accept'=>'text/plain, */*',
'X-Requested-With'=>'XMLHttpRequest',
'Referer'=>'https://mws.amazonservices.com/scratchpad/index.html',
'Accept-Encoding'=>'gzip, deflate, br',
'Accept-Language'=>'en-US,en;q=0.8',
],
'body'=>$body,
]);
$response = $client->request('POST', 'https://mws.amazonservices.com/Products/2011-10-01');
echo $response->getStatusCode();
?>