开发者

Amazon.com MWS Integration

I am currently developing a very basic site which will, at this time, simply display order information from Amazon's Marketplace.

  • I have all of the MWS Security Credentials.
  • I have downloaded and reviewed, with much confusion, the PHP Client Library.
  • I am kind of new to PHP but I feel like I can handle this project.

I need to know how to install and access information from this API. I feel like I've tried everything. Amazon does not supply enough information to get this going. They make it sound开发者_如何转开发 like it takes 5 or 6 easy steps and you can access your information; this is not true.

Is there a detailed tutorial on MWS? I need as much information as possible. If you can help me out, maybe outline the steps required to get it going, that would be very appreciated!!!! I'm pulling my hair out over this. Thanks again


A rough file to get you started. This is taken from several pages, including this one from @Vaidas. I don't have links yet, sorry. My only contribution is to put this together in one place.

None of the PHP code Amazon supplied worked for me out of the box. I'm assuming you have XAMPP with cURL or an equivalent environment. This code SHOULD work out of the box to get you started on what needs to happen. Just plug in your credentials.

<?php
$param = array();
$param['AWSAccessKeyId']   = 'YourAccessKeyID'; 
$param['Action']           = 'GetLowestOfferListingsForASIN'; 
$param['SellerId']         = 'YourSellerID'; 
$param['SignatureMethod']  = 'HmacSHA256';  
$param['SignatureVersion'] = '2'; 
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2011-10-01'; 
$param['MarketplaceId']    = 'YourMarketplaceID'; 
$param['ItemCondition']    = 'new';
$param['ASINList.ASIN.1']  = 'B00C5XBAOA';
$secret = 'YourSecretKey';

$url = array();
foreach ($param as $key => $val) {

    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";
}

sort($url);

$arr   = implode('&', $url);

$sign  = 'GET' . "\n";
$sign .= 'mws.amazonservices.com' . "\n";
$sign .= '/Products/2011-10-01' . "\n";
$sign .= $arr;

$signature = hash_hmac("sha256", $sign, $secret, true);
$signature = urlencode(base64_encode($signature));

$link  = "https://mws.amazonservices.com/Products/2011-10-01?";
$link .= $arr . "&Signature=" . $signature;
echo($link); //for debugging - you can paste this into a browser and see if it loads.

$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

echo('<p>' . $response . '</p>');
print_r('<p>' . $info . '</p>');
?>

Please note that it is VITAL to have the curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); line, at least in my case. CURL was working fine for any page except for the MWS page (it was just giving me a blank page with -1s in the info, and it took me most of a day to figure out I needed that line. It's in the MWS forums somewhere.

For good measure, here's a link to MWS ScratchPad.

Once I get a better handle on working with MWS maybe I'll do a tutorial. Or someone who is better at HTML and has a need for more of the features could do it.


in case you still didn't figure out how to do this, follow these steps

  • read the Developer Guide
  • read the Reports API Reference
  • RequestReport with some ReportType that will return order data (page 51 or so, look the reports api reference)
  • you can test this with the MWS Scratchpad
  • you can also post to the Amazon MWS community forum to get additional help
  • you can even write to the Amazon Tech Support

hope this helps you and other users.


Amazon provides some great sample code at https://developer.amazonservices.com/. I've successfully used their code for my PHP applications.

I agree. It was a nightmare to figure out the MWS API.


Some changes to @Josiah's method to make it work for other marketplaces:

Line:

$sign .= 'mws.amazonservices.com' . "\n";

Change to: your correct MWS endpoint. List here http://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html - it'll match your marketplace ID, which could be something like this:

$sign .= 'mws-eu.amazonservices.com' . "\n";

and UK marketplace ID for UK site.

Line:

$link  = "https://mws.amazonservices.com/Products/2011-10-01?";

Again, change the start of the url in line with above.

This'll probably give you straight text output in a browser (view source for xml). For XML visible output (easier for checking) do this:

Add an XML content type line to top of file:

header('Content-type: application/xml');

Then comment out:

echo($link);

and

print_r('<p>' . $info . '</p>');


Implementing MWS is easy if you follow the right steps: 1-Download the codebase library from the https://developer.amazonservices.com/ as per your preferred language. 2-Set your seller mws credentials in config.php file under sample folder so that same can be used while running the specific file under the sample folder like: RequestReportSample.php and set the report type and endpoint url for specific seller domain. 3- You can then check submitted request status from scratchpad. 4- You can use GetReportSample file to get the order report data and use the same as per your need.

You can follow the reference as well http://prashantpandeytech.blogspot.com/2015/03/mws-amazon-marketplace-web-service-api.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜