MuffinMan is a ruby interface to the Amazon Selling Partner API. For more information on registering to use the Selling Partner API, see Amazon's documentation
As of now, this gem only supports portions of the following APIs with more to come:
Customer Feedback Insights API v2024-06-01 (BETA)Amazon Warehousing and Distribution API v2024-05-09Catalog Items API v2022-04-01Data Kiosk API v2023-11-15FBA Inventory API v1Feeds API v2021-06-30Finances API v0Fulfillment Inbound API v2024-03-20Fulfillment Outbound API v2020-07-01Listings API v2021-08-01Listings API v2020-09-01Listings Restrictions API v2021-08-01Merchant Fulfillment API v0Notifications API v1Orders API v0Product Fees API v0Product Pricing API v0Reports API v2021-06-30Solicitations API v1Sellers API v1Tokens API v2021-03-01Vendor Direct Fulfillment Transactions API v1Vendor Direct Fulfillment Orders API v2021-12-28Vendor Direct Fulfillment Payments API v1Vendor Direct Fulfillment Shipping API v2021-12-28Vendor Direct Fulfillment Transactions API v2021-12-28Vendor Invoices API v1Vendor Orders API v1Vendor Shipments API v1Vendor Transaction Status API v1Uploads API v2020-11-01A+ API v2020-11-01Application Management API v2023-11-30Finances API v2024-06-19
Add this line to your application's Gemfile:
gem 'muffin_man'And then execute:
$ bundle install
Or install it yourself as:
$ gem install muffin_man
To make a call to the Amazon Selling Partner API, define your credentials and make a call as shown:
require 'muffin_man'
credentials = {
refresh_token: LWA_REFRESH_TOKEN,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
region: REGION, # This can be one of ['na', 'eu', 'fe'] and defaults to 'na'
access_token_cache_key: SELLING_PARTNER_ID, # Optional if you want access token caching
}
client = MuffinMan::Solicitations::V1.new(credentials)
response = client.create_product_review_and_seller_feedback_solicitation(amazon_order_id, marketplace_ids)
JSON.parse(response.body)You can optionally use Amazon's sandbox environment by specifying client = MuffinMan::Solicitations.new(credentials, sandbox = true)
By default MuffinMan will log to standard out. To customize the logger used:
MuffinMan.configure do |config|
config.logger = Logger.new('log/sp-api.log')
endYou can save and retrieve the LWA refresh token by defining a lambda in your initializers.
For example, if you are using Redis as your cache you could define:
@@redis = Redis.new
MuffinMan.configure do |config|
config.save_access_token = -> (access_token_cache_key, token) do
@@redis.set("SP-TOKEN-#{access_token_cache_key}", token['access_token'], ex: token['expires_in'])
end
config.get_access_token = -> (access_token_cache_key) { @@redis.get("SP-TOKEN-#{access_token_cache_key}") }
endTo retrieve the refresh token from an LWA Website authorization workflow, you can use the LWA helper:
# Get your auth code first, either through the Website oauth flow or Authorization API
credentials = {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
scope: 'sellingpartnerapi::migration' # Grantless scope for MWS migration
}
client = MuffinMan::Authorization::V1.new(credentials)
resp = JSON.parse(client.get_authorization_code(seller_id, developer_id, mws_auth_token).body)
auth_code = resp['payload']['authorizationCode']
# Then query retrieve the refresh token to store
refresh_token = MuffinMan::Lwa::AuthHelper.get_refresh_token(CLIENT_ID, CLIENT_SECRET, auth_code)To retrieve the access token, you can use the LWA helper:
access_token = MuffinMan::Lwa::AuthHelper.get_access_token(scope, client_id, client_secret)To rotate client secret for application
MuffinMan::ApplicationManagement::V20231130.rotate_application_client_secret(client_id,client_secret)To use Typheous' verbose mode set env variable MUFFIN_MAN_DEBUG=true
Bug reports and pull requests are welcome on GitHub at https://github.com/patterninc/muffin_man. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the MuffinMan project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.