How do you work with the data returned by list_orders?

170 views
Skip to first unread message

cm2015

unread,
Mar 26, 2015, 4:17:55 PM3/26/15
to boto-...@googlegroups.com
Hi everyone,

First off, the code we're using to pull the data is below:

from boto import mws

from boto.mws.connection import MWSConnection


accessKey
= "XXXX"
merchantID
= "XXXX"
marketplaceID
= "XXXX"
secretKey
= "XXXX"


mws
= MWSConnection(accessKey, secretKey)
mws
.Merchant = merchantID
mws
.SellerId = merchantID
mws
.MarketplaceId = marketplaceID
print mws.list_orders(CreatedAfter = '2015-03-25T00:00:00Z', MarketplaceId = [marketplaceID])


I have been trying to figure out what type of response we're getting when the orders are printed. The data looks like this (copied from another thread):

ListOrdersResponse{u'xmlns': u'https://mws.amazonservices.com/Orders/2013-09-01'}(ListOrdersResult: ListOrdersResult{}(LastUpdatedBefore: u'2014-08-25T22:09:12Z', Orders: ^Orders^{}(Order: [Order{}(LatestDeliveryDate: u'2014-09-02T22:59:59Z', LatestShipDate: u'2014-08-27T22:59:59Z', FulfillmentChannel: u'MFN', ShippingAddress: ^ShippingAddress^{}(City: u'xxxx', Name: u'xxx', CountryCode: u'xx', Phone: u'xxxxxx', AddressLine2: u'xxxx', AddressLine1: u'xxx', PostalCode: u'xxxx'), EarliestDeliveryDate: u'2014-08-28T23:00:00Z', PurchaseDate: u'2014-08-22T11:13:16Z', ShipmentServiceLevelCategory: u'Standard', OrderTotal: GBPxxx, AmazonOrderId: u'xxx', EarliestShipDate: u'2014-08-25T23:00:00Z', NumberOfItemsUnshipped: u'1', OrderStatus: u'Unshipped', OrderType: u'StandardOrder', PaymentExecutionDetail: None, ShippedByAmazonTFM: u'false', PaymentMethod: u'Other', SalesChannel: u'Amazon.co.uk', LastUpdateDate: u'2014-08-23T00:22:02Z', BuyerEmail: u'xxxxxxxxxxxx', ShipServiceLevel: u'Std UK Dom', BuyerName: u'xxxxxxxxxx', NumberOfItemsShipped: u'0', MarketplaceId: u'xxxxxxxxxx'))])), ResponseMetadata: ^ResponseMetadata^{}(RequestId: u'xxxxxxxxx'))


How would I go about extracting the AmazonOrderId from the above for example? Or how would I go about iterating through everything and printing it all on it's own line? Forgive me if this is a dumb question, I'm a python n00b and am trying desperately to make sense of the response we're receiving. The goal is to pull all of the order information and save it into a CSV for order processing.

Thank you for reading,

Clark

Dylan Drake

unread,
Apr 8, 2015, 12:29:42 PM4/8/15
to boto-...@googlegroups.com
Hello,  this is my first group i have ever joined and i can show you how i do it but i'm having trouble figuring out how to add code blocks so im just going to copy and paste it. 
  
from boto.mws.connection import MWSConnection

# Credentials
Marketplace_Id = 'XXXX'
Merchant_Id = 'XXXX'
Access_Key = 'XXXX'
Secret_Key = 'XXXX'

# Make connection
mws = MWSConnection(Access_Key, Secret_Key)

# pass Merchant_Id and Marketplace_Id to MWS
mws.SellerId = Merchant_Id
mws.Merchant = Merchant_Id
mws.MarketplaceId = Marketplace_Id

# Request order list and save to 'response'
response = mws.list_orders(CreatedAfter='Some_Time', MarketplaceId=[Marketplace_Id],
    OrderStatus=['Unshipped', 'PartiallyShipped'], FulfillmentChannel=['MFN'])
    
# Get orders and save them to list called 'orders'
orders = response.ListOrdersResult.Orders.Order

# Iterate through orders in 'orders'
for order in orders:
    
    # Get Amazon order id
    OrderId = order.AmazonOrderId


Hope this helps,
Dylan
Reply all
Reply to author
Forward
0 new messages