Amazon.com MWS Integration
Asked Answered
G

5

9

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

Gerrigerrie answered 8/9, 2011 at 18:41 Comment(1)
can't five upvote due to reputation limit, but want to confirm the valid input from @pepsi_max2k, that mws.amazonservices.com wasn't working for me but mws.amazonservices.com.au does, that makes the api hostname become so important, depending on where your account is signed upGerlachovka
S
11

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.

Spry answered 10/3, 2014 at 20:22 Comment(4)
Users keep in mind that this is for the depreciated APITransparent
Dont forget about some kind of backoff implementation in case you start getting "Request Throttled" repliesPeggie
you saved my life!Odontograph
Thanks! Did not expect easy solution as this oneDosimeter
C
10

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

hope this helps you and other users.

Chrysalis answered 10/5, 2012 at 18:20 Comment(0)
A
5

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.

Acoustic answered 17/10, 2011 at 13:43 Comment(1)
I don't have any code to interface with Amazon stores. Sorry.Acoustic
L
0

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>');
Laurilaurianne answered 29/1, 2015 at 17:2 Comment(1)
Thanks pepsi_max. Welcome to Stack Overflow! It's generally a good idea to keep your answers free of personal content, but I'm so glad that code helped you, and you make good points about turning my code into production-ready code. You may want to edit your answer to be a bit more concise. Tip: be extremely careful with matching the ASINs to EANs. You'll need to run batches of GetMatchingProductForId then whatever other info you need. Send me an email and I'll give you some other pointers if you want - it's in my profile.Spry
I
0

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

Include answered 20/3, 2015 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.