How to get started with MWS?

764 views
Skip to first unread message

Alex

unread,
May 1, 2014, 2:56:24 PM5/1/14
to boto-...@googlegroups.com
Hi everyone,

I am happy that I discovered boto, as it seems to be
super-comprehensive, doing all the heavy-lifting for me. My goal is to
answer the question "how many orders [of any product] did we have on a
certain day?", and it seems that MWSConnection is what I need.

This is the code I was hoping would achieve that:

```
from boto.mws.connection import MWSConnection

mws = MWSConnection('xxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyyyyyyyyyyyy')
mws.SellerId = 'zzzzzzzzzzzzz'
mws.Merchant='zzzzzzzzzzzzz'
mws.list_orders(CreatedAfter='2014-04-25T12:00:00Z', MarketplaceId =
'qqqqqqqqqqqqqq')
```

This returns an error

MWS Response Error: 401 ResponseError
Undefined response error.
Access to Orders.ListOrders is denied


It sounds like reasonable behaviour, i.e. boto is doing everything
according to the protocol, and the server faithfully returns an error
because some permissions are not satisfied.

However, I still have some doubts and I would like to request advice
on how to use boto correctly.

1. What is the difference between MerchantId and SellerId?
I set them both to the same value, after getting one of these
responses KeyError: 'ListOrders requires SellerId argument. Set the
MWSConnection.SellerId attribute?'

Are they both necessary and should they be set to the same value?

2. Am I correct in assuming that CreatedAfter must be an ISO8601
timestamp, as in my example?


To rule out that the latter, I tried another API call:

mws.list_order_items(AmazonOrderId='002-9xxxxxx-1yyyyyy')

However, this results in the same type of error:

MWS Response Error: 401 ResponseError
Undefined response error.
Access to Orders.ListOrderItems is denied




Is there something else one needs to do before making these calls?
Perhaps there's a checkbox that needs to be ticked in the Amazon
Seller Central?



Your help will be greatly appreciated.

Andy Davidoff

unread,
May 1, 2014, 5:38:30 PM5/1/14
to boto-...@googlegroups.com
Alex, do any calls work? Can you do an `mws.get_orders_service_status()`?

I assume you know that the access key and secret key you use with MWS differ from those you use with the other AWS services. Also, you can more simply set the Merchant and SellerId using the keyword argument `Merchant` during your instantiation of `MWSConnection()`.

No special action is necessary in any web console.

--
Andy Davidoff
disruptek.com
1-877-DISRPTK

Alex

unread,
May 2, 2014, 2:59:43 AM5/2/14
to boto-...@googlegroups.com
Hi Andy,

Thank you for the reply. mws.get_orders_service_status() worked fine,
so I assumed that confirmed that the keys and identifiers were right.

I found how to enable the log and examined it, and realized what was
causing the problem. So, this message is for future generations of
archaeologists looking for answers :-)


This is a relevant fragment:

DEBUG:boto:query string:
AWSAccessKeyId=xxxxxxxxxxxxxxxxx&Action=ListOrders&CreatedAfter=2014-01-25T12%3A00%3A00Z&MarketplaceId.Id.1=A&MarketplaceId.Id.10=0&MarketplaceId.Id.11=D&MarketplaceId.Id.12=E&MarketplaceId.Id.13=R&MarketplaceId.Id.2=T&MarketplaceId.Id.3=V&MarketplaceId.Id.4=P&MarketplaceId.Id.5=D&MarketplaceId.Id.6=K&MarketplaceId.Id.7=I&MarketplaceId.Id.8=K&MarketplaceId.Id.9=X&SellerId=yyyyyyyyyyyyyyyyy&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2014-05-02T06%3A29%3A35Z&Version=2011-01-01


The MarketplaceId variables look weird, in fact it is each character
in the given ID. So it means that somewhere deep inside boto iterated
over that identifier; in this case it iterated over each character of
a string, but most likely it assumes that what it iterates through is
a list of marketplaceIds.

For those who are interested, this is what actually works:

from boto.mws.connection import MWSConnection

merchantId = 'abcabcabcabc'
marketplaceId = 'xyzxyzxyzxyz'
accessKeyId = 'tralatralatralatrla'
secretKey = 'secsecsecsecsecsec'

mws = MWSConnection(accessKeyId, secretKey, Merchant=merchantId)

#mws.list_orders(CreatedAfter='2014-01-25T12:00:00Z', MarketplaceId =
marketplaceId) #wrong
mws.list_orders(CreatedAfter='2014-01-25T12:00:00Z', MarketplaceId =
[marketplaceId]) #right




Well, I must say I am very I am very pleased with the result I get
with a few lines of code. A couple of years ago I solved this problem
using an older version of the API, based on CSV files and... aargh...
Boto is miles ahead! I'm very impressed!


Thank you all :-)

Andy Davidoff

unread,
May 2, 2014, 11:57:57 PM5/2/14
to boto-...@googlegroups.com
Sorry about that, I should have recognized the error in your first message. I’ll take a look at fixing this behavior so boto either throws a more useful error message or just wraps the `MerchantId` in an array.

BTW, you can use the API method docstring to get some help on required arguments, etc.

Have fun,
Reply all
Reply to author
Forward
0 new messages