Peddler is a Ruby Gem that can be used to access Amazon Marketplace Web Service (Amazon MWS) from Ruby. The following are some Ruby snippets that can be used to write a Ruby script that accesses MWS or to make ad-hoc queries against MWS from within IRb (Interactive Ruby.
Install Peddler Gem:
gem install peddler Successfully installed excon-0.45.3 Successfully installed jeff-1.3.0 Successfully installed peddler-0.16.0
You may have to use sudo, depending on how you installed RubyGems.
Setup the Peddler client instance:
require 'peddler' # Setup client client = MWS::Orders::Client.new({ :primary_marketplace_id => "ATVPD00000000", # Marketplace ID :merchant_id => "A1UX7000000000", # Seller ID :aws_access_key_id => "AKIAJ000000000000000", # AWS Access Key ID :aws_secret_access_key => "fT+tcCTUBUsd7w00000000000000000000000000" # Secret Key }) # Setup error callback. This helps debugging Amazon API error messages. client.on_error{|req,resp| puts resp.body } # Get API Status puts client.get_service_status
The following are some of the ways you can query MWS orders:
# Retrieve orders. CreatedAfter or LastUpdatedAfter must be specified. # - created_after # - created_before # - last_updated_after # - last_updated_before # - order_status (Unshipped, Shipped, Canceled) resp1 = client.list_orders(:created_after => '2015-05-01') puts resp1.body resp2 = client.list_orders(:created_after => '2015-05-01', :order_status => ['Unshipped', 'PartiallyShipped']) puts resp2.body resp3 = client.list_orders(:created_after => '2015-05-01', :order_status => ['Shipped']) puts resp3.body
These are some documentation pages that were helpful when investigating Peddler:
- Peddler
- https://github.com/hakanensari/peddler
- Peddler API Docs
- MWS::Orders::Client
- MWS::Orders::Client#list_orders
- Amazon API Docs
- List Orders