peddler 2.4.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +402 -140
  3. data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +92 -0
  4. data/lib/peddler/api/aplus_content_2020_11_01.rb +246 -0
  5. data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
  6. data/lib/peddler/api/application_management_2023_11_30.rb +35 -0
  7. data/lib/peddler/api/catalog_items_2020_12_01.rb +81 -0
  8. data/lib/peddler/api/catalog_items_2022_04_01.rb +93 -0
  9. data/lib/peddler/api/catalog_items_v0.rb +103 -0
  10. data/lib/peddler/api/data_kiosk_2023_11_15.rb +108 -0
  11. data/lib/peddler/api/easy_ship_2022_03_23.rb +127 -0
  12. data/lib/peddler/api/fba_inbound_eligibility_v1.rb +44 -0
  13. data/lib/peddler/api/fba_inventory_v1.rb +122 -0
  14. data/lib/peddler/api/feeds_2021_06_30.rb +122 -0
  15. data/lib/peddler/api/finances_2024_06_19.rb +50 -0
  16. data/lib/peddler/api/finances_v0.rb +148 -0
  17. data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +759 -0
  18. data/lib/peddler/api/fulfillment_inbound_v0.rb +352 -0
  19. data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +259 -0
  20. data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
  21. data/lib/peddler/api/listings_items_2020_09_01.rb +95 -0
  22. data/lib/peddler/api/listings_items_2021_08_01.rb +170 -0
  23. data/lib/peddler/api/listings_restrictions_2021_08_01.rb +47 -0
  24. data/lib/peddler/api/merchant_fulfillment_v0.rb +80 -0
  25. data/lib/peddler/api/messaging_v1.rb +273 -0
  26. data/lib/peddler/api/notifications_v1.rb +145 -0
  27. data/lib/peddler/api/orders_v0.rb +279 -0
  28. data/lib/peddler/api/product_fees_v0.rb +77 -0
  29. data/lib/peddler/api/product_pricing_2022_05_01.rb +54 -0
  30. data/lib/peddler/api/product_pricing_v0.rb +162 -0
  31. data/lib/peddler/api/product_type_definitions_2020_09_01.rb +86 -0
  32. data/lib/peddler/api/replenishment_2022_11_07.rb +57 -0
  33. data/lib/peddler/api/reports_2021_06_30.rb +163 -0
  34. data/lib/peddler/api/sales_v1.rb +77 -0
  35. data/lib/peddler/api/sellers_v1.rb +45 -0
  36. data/lib/peddler/api/services_v1.rb +348 -0
  37. data/lib/peddler/api/shipment_invoicing_v0.rb +59 -0
  38. data/lib/peddler/api/shipping_v1.rb +132 -0
  39. data/lib/peddler/api/shipping_v2.rb +319 -0
  40. data/lib/peddler/api/solicitations_v1.rb +63 -0
  41. data/lib/peddler/api/supply_sources_2020_07_01.rb +100 -0
  42. data/lib/peddler/api/tokens_2021_03_01.rb +38 -0
  43. data/lib/peddler/api/uploads_2020_11_01.rb +50 -0
  44. data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +32 -0
  45. data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +84 -0
  46. data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +84 -0
  47. data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +31 -0
  48. data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +45 -0
  49. data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +203 -0
  50. data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +189 -0
  51. data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +32 -0
  52. data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +32 -0
  53. data/lib/peddler/api/vendor_invoices_v1.rb +30 -0
  54. data/lib/peddler/api/vendor_orders_v1.rb +159 -0
  55. data/lib/peddler/api/vendor_shipments_v1.rb +132 -0
  56. data/lib/peddler/api/vendor_transaction_status_v1.rb +33 -0
  57. data/lib/peddler/api.rb +138 -0
  58. data/lib/peddler/endpoint.rb +51 -0
  59. data/lib/peddler/error.rb +31 -0
  60. data/lib/peddler/marketplace.rb +38 -68
  61. data/lib/peddler/token.rb +70 -0
  62. data/lib/peddler/version.rb +1 -1
  63. data/lib/peddler.rb +56 -1
  64. metadata +74 -80
  65. data/lib/mws/easy_ship/client.rb +0 -93
  66. data/lib/mws/easy_ship.rb +0 -3
  67. data/lib/mws/feeds/client.rb +0 -122
  68. data/lib/mws/feeds.rb +0 -3
  69. data/lib/mws/finances/client.rb +0 -82
  70. data/lib/mws/finances.rb +0 -3
  71. data/lib/mws/fulfillment_inbound_shipment/client.rb +0 -388
  72. data/lib/mws/fulfillment_inbound_shipment.rb +0 -3
  73. data/lib/mws/fulfillment_inventory/client.rb +0 -57
  74. data/lib/mws/fulfillment_inventory.rb +0 -3
  75. data/lib/mws/fulfillment_outbound_shipment/client.rb +0 -211
  76. data/lib/mws/fulfillment_outbound_shipment.rb +0 -3
  77. data/lib/mws/merchant_fulfillment/client.rb +0 -87
  78. data/lib/mws/merchant_fulfillment.rb +0 -3
  79. data/lib/mws/off_amazon_payments.rb +0 -3
  80. data/lib/mws/orders/client.rb +0 -120
  81. data/lib/mws/orders.rb +0 -3
  82. data/lib/mws/products/client.rb +0 -268
  83. data/lib/mws/products.rb +0 -3
  84. data/lib/mws/recommendations/client.rb +0 -72
  85. data/lib/mws/recommendations.rb +0 -3
  86. data/lib/mws/reports/client.rb +0 -236
  87. data/lib/mws/reports.rb +0 -3
  88. data/lib/mws/sellers/client.rb +0 -44
  89. data/lib/mws/sellers.rb +0 -3
  90. data/lib/mws/shipment_invoicing/client.rb +0 -74
  91. data/lib/mws/shipment_invoicing.rb +0 -3
  92. data/lib/mws/subscriptions/client.rb +0 -179
  93. data/lib/mws/subscriptions.rb +0 -3
  94. data/lib/mws.rb +0 -29
  95. data/lib/peddler/client.rb +0 -159
  96. data/lib/peddler/errors/builder.rb +0 -64
  97. data/lib/peddler/errors/class_generator.rb +0 -40
  98. data/lib/peddler/errors/error.rb +0 -45
  99. data/lib/peddler/errors/parser.rb +0 -28
  100. data/lib/peddler/flat_file_parser.rb +0 -56
  101. data/lib/peddler/headers.rb +0 -102
  102. data/lib/peddler/operation.rb +0 -78
  103. data/lib/peddler/parser.rb +0 -33
  104. data/lib/peddler/structured_list.rb +0 -23
  105. data/lib/peddler/vcr_matcher.rb +0 -97
  106. data/lib/peddler/xml_parser.rb +0 -38
  107. data/lib/peddler/xml_response_parser.rb +0 -25
data/README.md CHANGED
@@ -1,244 +1,506 @@
1
1
  # Peddler
2
2
 
3
- [![Build](https://github.com/hakanensari/peddler/workflows/build/badge.svg)](https://github.com/hakanensari/peddler/actions)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/maintainability)](https://codeclimate.com/github/hakanensari/peddler/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/test_coverage)](https://codeclimate.com/github/hakanensari/peddler/test_coverage)
3
+ [![Build](https://github.com/hakanensari/peddler/workflows/build/badge.svg)][build]
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/maintainability)][maintainability]
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/test_coverage)][test-coverage]
6
6
 
7
- > :boom: Amazon is migrating to the newly-launched Selling Partner API (SP-API) and is no longer granting new users access to the MWS APIs. I hope to add support in Peddler in due course.
7
+ **Peddler** is a Ruby interface to the [Amazon Selling Partner API (SP-API)][docs-overview]. The SP-API enables Amazon sellers and vendors to programmatically access their data on orders, shipments, payments, and more.
8
8
 
9
- **Peddler** is a Ruby interface to the [Amazon MWS API](https://developer.amazonservices.com/), a collection of web services that help Amazon sellers programmatically exchange data on their listings, orders, payments, reports, and more.
10
-
11
- To use Amazon MWS, you must have an eligible seller account and [register as a developer](https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Registering.html#DG_Registering__RegisteringAsADeveloper). You can then access your own selling account using its merchant ID—note that Amazon also refers to this as seller ID or merchant token in different places.
12
-
13
- Amazon has [multiple regions](https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html). Each region requires application developers to register individually. Some MWS API sections may require additional authorisation from Amazon.
9
+ To begin using the Amazon SP-API, you must [register as a developer][register-as-developer] and [register your application][register-application]. Once registered, [obtain your Login with Amazon (LWA) credentials][view-credentials] to access your own or other selling partners' data.
14
10
 
15
11
  ![Peddler](https://github.com/hakanensari/peddler/blob/main/images/peddler.jpg?raw=true)
16
12
 
17
- ## Usage
13
+ ## Installation
18
14
 
19
- Require the library.
15
+ Add this line to your Gemfile.
20
16
 
21
17
  ```ruby
22
- require "peddler"
18
+ gem "peddler", "3.0.0.beta1"
23
19
  ```
24
20
 
25
- A client requires the AWS credentials of the application developer. If you are working in a single MWS region, you can set them globally.
26
-
21
+ And then execute:
27
22
 
28
- ```bash
29
- export AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
30
- export AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
23
+ ```shell
24
+ bundle install
31
25
  ```
32
26
 
33
- Now, create a client with the Amazon marketplace you signed up on and a merchant ID. Peddler provides a class for each API section under an eponymous namespace.
27
+ ## Usage
34
28
 
35
- ```ruby
36
- client = MWS.orders(marketplace: "ATVPDKIKX0DER",
37
- merchant_id: "123")
29
+ Set your LWA credentials in your environment.
38
30
 
39
- # or a shorthand
40
- client = MWS.orders(marketplace: "US",
41
- merchant_id: "123")
31
+ ```shell
32
+ export LWA_CLIENT_ID=<YOUR_CLIENT_ID>
33
+ export LWA_CLIENT_SECRET=<YOUR_CLIENT_SECRET>
42
34
  ```
43
35
 
44
- If you are creating a [client for another seller](https://developer.amazonservices.com/gp/mws/faq.html#developForSeller), pass an MWS Auth Token as well.
36
+ Require the library.
45
37
 
46
38
  ```ruby
47
- client = MWS.orders(marketplace: "ATVPDKIKX0DER",
48
- merchant_id: "123",
49
- auth_token: "123")
39
+ require "peddler"
50
40
  ```
51
41
 
52
- You won't be able to create a client for another seller if you are in different regions.
42
+ ### Authorization
53
43
 
54
- If you are working with sellers across multiple regions, a single set of credentials will not be enough. In that case, do not use global environment variables and pass your AWS credentials when creating the client.
44
+ A seller or vendor [provides you a refresh token][authorization] to access their data on Amazon.
55
45
 
56
46
  ```ruby
57
- client = MWS.orders(marketplace: "ATVPDKIKX0DER",
58
- merchant_id: "123",
59
- aws_access_key_id: "123",
60
- aws_secret_access_key: "123")
47
+ refresh_token = Peddled::Token.request(
48
+ code: "<AUTHORIZATION_CODE>"
49
+ ).parse["refresh_token"]
61
50
  ```
62
51
 
63
- Once you have a client with valid credentials, you should be able to make requests to the API. Clients map operation names in a flat structure. Methods have positional arguments for required input and keyword arguments for optional parameters. Both method and argument names are underscored but otherwise identical to the names of the corresponding operations and parameters documented in the API.
64
-
65
- For instance, using the above MWS Orders client:
52
+ You use this to generate a temporary access token to authenticate individual API requests.
66
53
 
67
54
  ```ruby
68
- response = client.list_orders('ATVPDKIKX0DER')
55
+ access_token = Peddler::Token.request(
56
+ refresh_token: "<REFRESH_TOKEN>",
57
+ ).parse["access_token"]
69
58
  ```
70
59
 
71
- ### Parser
72
-
73
- Peddler wraps successful responses in a generic parser that handles both XML documents and flat files:
60
+ Similarly, you can request a token for grantless operations.
74
61
 
75
62
  ```ruby
76
- response = client.get_service_status
77
- response.parse # will return a Hash object
78
- response.dig('Status') # delegates to Hash#dig
63
+ access_token = Peddler::Token.request(
64
+ scope: "sellingpartnerapi::notifications",
65
+ ).parse["access_token"]
79
66
  ```
80
67
 
81
- You can swap this with a purpose-built parser.
68
+ If you haven’t set your LWA credentials as environment variables, pass them directly when requesting the token.
82
69
 
83
70
  ```ruby
84
- MWS::Orders::Client.parser = MyParser
71
+ access_token = Peddler::Token.request(
72
+ client_id: "<YOUR_CLIENT_ID>",
73
+ client_secret: "<YOUR_CLIENT_SECRET>",
74
+ refresh_token: "<REFRESH_TOKEN>",
75
+ ).parse["access_token"]
85
76
  ```
86
77
 
87
- For a sample implementation, see my [MWS Orders](https://github.com/hakanensari/mws-orders) library.
88
-
89
- ### Throttling
78
+ Access tokens are valid for one hour. To optimize performance, cache the token and reuse across calls.
90
79
 
91
- Amazon limits the number of requests you can submit to some operations in a given amount of time. When you hit a limit, your request throws a `Peddler::Errors::RequestThrottled` error.
92
-
93
- You will want to exit or back off exponentially and retry if you hit this error.
80
+ In Rails, if you're storing a refresh token in a model representing a selling partner, implement a method there to retrieve and cache access tokens:
94
81
 
95
82
  ```ruby
96
- begin
97
- client.throttled_method
98
- rescue Peddler::Errors::RequestThrottled
99
- back_off_exponentially
100
- retry
83
+ class Seller
84
+ "..."
85
+
86
+ def access_token
87
+ Rails.cache.fetch("#{cache_key}/access_key", expires_in: 1.hour) do
88
+ Peddler::Token.request(
89
+ refresh_token:,
90
+ ).parse["access_token"]
91
+ end
92
+ end
101
93
  end
102
94
  ```
103
95
 
104
- Some API sections also have an hourly request quota in addition to the numerical request quota. When you hit this quota, your request throws a `Peddler::Errors::QuotaExceeded` error.
96
+ ### Rate limiting
105
97
 
106
- You can introspect your quota usage on the parsed response:
98
+ Amazon’s Selling Partner API (SP-API) imposes [rate limits][rate-limits] on most operations. Peddler respects these limits and automatically backs off when throttled. To override the default rate limit, pass a `:rate_limit` argument when running an operation.
107
99
 
108
- ```ruby
109
- response = client.method_with_quota
110
- puts response.mws_quota_remaining
111
- # 150
100
+ **Note:** This functionality requires version 6 of the underlying [HTTP library][httprb]. As of writing, this is not released yet. To use rate limiting, point to their main branch on GitHub.
112
101
 
113
- begin
114
- client.method_with_quota
115
- rescue Peddler::Errors::QuotaExceeded => error
116
- puts error.response.mws_quota_remaining
117
- # 0
118
- end
119
- ```
102
+ ### The APIs
120
103
 
121
- Read [tips on how to avoid throttling](https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Throttling.html).
104
+ Peddler provides a class for each API version under an eponymous namespace. Below is a list of the more important APIs, along with brief descriptions and code examples to help you get started.
122
105
 
123
- ### Debugging
106
+ #### Catalog Items API (2022-04-01)
124
107
 
125
- If you are having trouble with a request, read the [Amazon documentation](https://developer.amazonservices.com/gp/mws/docs.html). [Peddler's source](https://www.rubydoc.info/github/hakanensari/peddler) also links individual operations to their corresponding entries in the Amazon docs.
108
+ Provides programmatic access to Amazon's catalog data, such as item titles, descriptions, and other product details.
126
109
 
127
- Note that some optional keywords have default values.
110
+ ```ruby
111
+ api = Peddler.catalog_items_2022_04_01(aws_region, access_token)
112
+ response = api.get_catalog_item(
113
+ marketplaceIds: ["ATVPDKIKX0DER"],
114
+ asin: "B08N5WRWNW"
115
+ )
116
+ items = response.parse.dig("items")
117
+ ```
128
118
 
129
- To introspect requests, set the `EXCON_DEBUG` environment variable to `1` or similar truthy value. Peddler will then log request and response internals to stdout.
119
+ #### Orders API (v0)
130
120
 
131
- If you contact Amazon MWS support, they will ask you for the **RequestId** and **Timestamp** of affected requests.
121
+ Allows you to retrieve order information, including order details, buyer information, and order items.
132
122
 
133
123
  ```ruby
134
- response = client.problem_method
135
- puts response.mws_request_id
136
- puts response.mws_timestamp
124
+ api = Peddler.orders_v0(aws_region, access_token)
125
+ response = api.get_orders(
126
+ marketplaceIds: ["ATVPDKIKX0DER"],
127
+ createdAfter: "2023-01-01T00:00:00Z"
128
+ )
129
+ response.parse.dig("orders")
137
130
  ```
138
131
 
139
- You can access the same attributes on `error.response`. See <a href="#throttling">above example</a>.
132
+ #### Feeds API (2021-06-30)
140
133
 
141
- ## The APIs
134
+ Enables you to upload data to Amazon for updating listings, prices, inventory, and more.
142
135
 
143
- ### Easy Ship
136
+ ```ruby
137
+ api = Peddler.feeds_2021_06_30(aws_region, access_token)
138
+
139
+ # Create a feed document to get an upload URL
140
+ response = api.create_feed_document(
141
+ contentType: "text/xml; charset=UTF-8"
142
+ )
143
+ feed_document_id = response.parse["feedDocumentId"]
144
+ upload_url = response.parse["url"]
145
+
146
+ # Upload the feed content to the provided URL
147
+ feed_content = File.read("inventory_update.xml")
148
+ api.upload_feed_document(upload_url, feed_content)
149
+
150
+ # Create the feed
151
+ response = api.create_feed(
152
+ feedType: "POST_INVENTORY_AVAILABILITY_DATA",
153
+ marketplaceIds: ["ATVPDKIKX0DER"],
154
+ inputFeedDocumentId: feed_document_id
155
+ )
156
+ response.parse["feedId"]
157
+ ```
144
158
 
145
- With the Easy Ship API, you can build applications that help sellers in India manage and ship their Amazon Easy Ship orders. Your Amazon Easy Ship applications can get available pickup slots; schedule, reschedule, and cancel pickups; and print labels, invoices, and warranties.
159
+ #### Reports API (2021-06-30)
146
160
 
147
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/easy_ship/EasyShip_Overview.html)
148
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/EasyShip/Client)
161
+ Allows you to request and download various reports, such as order and inventory reports.
149
162
 
150
- ### Feeds
163
+ ```ruby
164
+ api = Peddler.reports_2021_06_30(aws_region, access_token)
165
+ response = api.create_report(
166
+ reportType: "GET_FLAT_FILE_OPEN_LISTINGS_DATA",
167
+ marketplaceIds: ["ATVPDKIKX0DER"]
168
+ )
169
+ response.parse["reportId"]
170
+ ```
151
171
 
152
- The MWS Feeds API lets you upload inventory and order data to Amazon. You can also use this API to get information about the processing of feeds.
172
+ #### Listings Items API (2021-08-01)
153
173
 
154
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/feeds/Feeds_Overview.html)
155
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Feeds/Client)
156
- - [XML schema docs](https://sellercentral.amazon.com/gp/help/help-page.html?itemID=1611)
174
+ Enables you to manage your product listings on Amazon, including creating, updating, and deleting listings.
157
175
 
158
- ### Finances
176
+ ```ruby
177
+ api = Peddler.listings_items_2021_08_01(aws_region, access_token)
178
+ response = api.put_listings_item(
179
+ "<SELLER_ID>",
180
+ "SKU123",
181
+ "ATVPDKIKX0DER",
182
+ body: {
183
+ productType: "PRODUCT",
184
+ requirements: "LISTING",
185
+ attributes: {
186
+ title: [{ value: "New Product Title" }],
187
+ description: [{ value: "Product description goes here." }],
188
+ bullet_point: [{ value: "Feature 1" }, { value: "Feature 2" }],
189
+ manufacturer: [{ value: "Your Brand" }]
190
+ }
191
+ }
192
+ )
193
+ response.parse
194
+ ```
159
195
 
160
- The MWS Finances API enables you to obtain financial information relevant to your business with Amazon. You can obtain financial events for a given order, financial event group, or date range without having to wait until a statement period closes. You can also obtain financial event groups for a given date range.
196
+ #### Notifications API (v1)
161
197
 
162
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/finances/Finances_Overview.html)
163
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Finances/Client)
198
+ Allows you to subscribe to notifications for specific events like order status updates or feed processing statuses.
164
199
 
165
- ### Fulfillment Inbound Shipment
200
+ ```ruby
201
+ api = Peddler.notifications_v1(aws_region, access_token)
202
+ # Create a destination
203
+ response = api.create_destination(
204
+ name: "MySQSQueue",
205
+ resourceSpecification: {
206
+ sqs: {
207
+ arn: "arn:aws:sqs:us-east-1:123456789012:MyQueue"
208
+ }
209
+ }
210
+ )
211
+ destination_id = response.parse["destinationId"]
212
+
213
+ # Create a subscription
214
+ response = api.create_subscription(
215
+ notificationType: "ANY_OFFER_CHANGED",
216
+ destinationId: destination_id
217
+ )
218
+ subscription = response.parse
219
+ ```
166
220
 
167
- With the MWS Fulfillment Inbound Shipment API, you can create and update inbound shipments of inventory in the Amazon Fulfillment Network. You can also also request lists of inbound shipments or inbound shipment items based on criteria that you specify.
221
+ #### Product Fees API (v0)
168
222
 
169
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_Overview.html)
170
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentInboundShipment/Client)
223
+ Provides information about fees that may be charged for selling products on Amazon.
171
224
 
172
- ### Fulfillment Inventory
225
+ ```ruby
226
+ api = Peddler.product_fees_v0(aws_region, access_token)
227
+ response = api.get_my_fees_estimate_for_sku(
228
+ sellerId: "<YOUR_SELLER_ID>",
229
+ sku: "SKU123",
230
+ body: {
231
+ FeesEstimateRequest: {
232
+ MarketplaceId: "ATVPDKIKX0DER",
233
+ IsAmazonFulfilled: true,
234
+ PriceToEstimateFees: {
235
+ ListingPrice: {
236
+ CurrencyCode: "USD",
237
+ Amount: 25.00
238
+ }
239
+ }
240
+ }
241
+ }
242
+ )
243
+ fees_estimate = response.parse
244
+ ```
173
245
 
174
- The MWS Fulfillment Inventory API can help you stay up-to-date on the availability of your inventory in the Amazon Fulfillment Network. The Fulfillment Inventory API reports real-time availability information for your Amazon Fulfillment Network inventory regardless of whether you are selling your inventory on Amazon's retail web site or through other retail channels.
246
+ #### Fulfillment Outbound API (2020-07-01)
175
247
 
176
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_inventory/FBAInventory_Overview.html)
177
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentInventory/Client)
248
+ Allows you to create and manage fulfillment orders using Amazon's fulfillment network.
178
249
 
179
- ### Fulfillment Outbound Shipment
250
+ ```ruby
251
+ api = Peddler.fulfillment_outbound_2020_07_01(aws_region, access_token)
252
+ response = api.create_fulfillment_order(
253
+ body: {
254
+ sellerFulfillmentOrderId: "ORDER123",
255
+ displayableOrderId: "ORDER123",
256
+ displayableOrderDate: Time.now.iso8601,
257
+ displayableOrderComment: "Thank you for your order!",
258
+ shippingSpeedCategory: "Standard",
259
+ destinationAddress: {
260
+ name: "John Doe",
261
+ addressLine1: "123 Main St",
262
+ city: "Anytown",
263
+ stateOrRegion: "NY",
264
+ postalCode: "12345",
265
+ countryCode: "US"
266
+ },
267
+ items: [
268
+ {
269
+ sellerSku: "SKU123",
270
+ sellerFulfillmentOrderItemId: "ITEM123",
271
+ quantity: 1
272
+ }
273
+ ]
274
+ }
275
+ )
276
+ response.parse
277
+ ```
180
278
 
181
- The MWS Fulfillment Outbound Shipment API enables you to fulfill orders placed through channels other than Amazon's retail web site, using your inventory in the Amazon Fulfillment Network. You can request previews of potential fulfillment orders that return estimated shipping fees and shipping dates based on shipping speed. You can get detailed item-level, shipment-level, and order-level information for any existing fulfillment order that you specify. You can also request lists of existing fulfillment orders based on when they were fulfilled and by the fulfillment method associated with them.
279
+ #### Merchant Fulfillment API (v0)
182
280
 
183
- Support for creating and cancelling fulfillment orders has been implemented, but the rest of the API is not supported yet.
281
+ Allows you to create shipping labels for orders using Amazon's negotiated shipping rates.
184
282
 
185
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_outbound/FBAOutbound_Overview.html)
186
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentOutboundShipment/Client)
283
+ ```ruby
284
+ api = Peddler.merchant_fulfillment_v0(aws_region, access_token)
285
+ response = api.get_eligible_shipping_services(
286
+ body: {
287
+ shipmentRequestDetails: {
288
+ amazonOrderId: "ORDER123",
289
+ itemList: [
290
+ {
291
+ orderItemId: "ITEM123",
292
+ quantity: 1
293
+ }
294
+ ],
295
+ shipFromAddress: {
296
+ name: "Your Company",
297
+ addressLine1: "123 Warehouse Ave",
298
+ city: "Anytown",
299
+ stateOrRegion: "NY",
300
+ postalCode: "12345",
301
+ countryCode: "US"
302
+ },
303
+ packageDimensions: {
304
+ length: 10,
305
+ width: 5,
306
+ height: 8,
307
+ unit: "INCHES"
308
+ },
309
+ weight: {
310
+ value: 2,
311
+ unit: "POUNDS"
312
+ },
313
+ shippingServiceOptions: {
314
+ deliveryExperience: "DELIVERY_CONFIRMATION_WITHOUT_SIGNATURE",
315
+ carrierWillPickUp: false
316
+ }
317
+ }
318
+ }
319
+ )
320
+ shipping_services = response.parse["shippingServiceList"]
321
+ ```
187
322
 
188
- ### Merchant Fulfillment
323
+ #### Vendor Orders API (2021-12-29)
189
324
 
190
- The Merchant Fulfillment API provides programmatic access to Amazon’s fulfillment shipping services for sellers, including competitive rates with Amazon-partnered carriers. Sellers can find out what shipping services are available by submitting information about a proposed fulfillment shipment, such as package size and weight; shipment origin and destination; and delivery date requirements. Sellers can choose from the shipping service options returned by Amazon, and then receive shipping labels for fulfilling their orders.
325
+ Allows vendors to retrieve purchase orders and order details from Amazon.
191
326
 
192
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Overview.html)
193
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/MerchantFulfillment/Client)
327
+ ```ruby
328
+ api = Peddler.vendor_orders_2021_12_28(aws_region, access_token)
329
+ response = api.get_purchase_orders(
330
+ shipToPartyId: "<PARTY_ID>",
331
+ limit: 10,
332
+ createdAfter: "2023-01-01T00:00:00Z"
333
+ )
334
+ purchase_orders = response.parse["purchaseOrders"]
335
+ ```
194
336
 
195
- ### Orders
337
+ #### Vendor Direct Fulfillment Shipping API (2021-12-28)
196
338
 
197
- With the MWS Orders API, you can list orders created or updated during a time frame you specify or retrieve information about specific orders.
339
+ Enables vendors to manage shipping labels and shipping information for direct fulfillment orders.
198
340
 
199
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Overview.html)
200
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Orders/Client)
201
341
 
202
- ### Products
342
+ ```ruby
343
+ api = Peddler.vendor_direct_fulfillment_shipping_2021_12_28(aws_region, access_token)
344
+ response = api.get_packing_slip(
345
+ purchaseOrderNumber: "PO123456789"
346
+ )
347
+ response.parse
348
+ ```
203
349
 
204
- The MWS Products API helps you get information to match your products to existing product listings on Amazon Marketplace websites and to make sourcing and pricing decisions for listing those products on Amazon Marketplace websites.
350
+ #### Vendor Direct Fulfillment Orders API (2021-12-28)
205
351
 
206
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/products/Products_Overview.html)
207
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Products/Client)
352
+ Allows vendors to receive orders for direct fulfillment and provide shipment confirmations.
208
353
 
209
- ### Recommendations
210
354
 
211
- The Recommendations API enables you to programmatically retrieve Amazon Selling Coach recommendations by recommendation category. A recommendation is an actionable, timely, and personalized opportunity to increase your sales and performance.
355
+ ```ruby
356
+ api = Peddler.vendor_direct_fulfillment_orders_2021_12_28(aws_region, access_token)
357
+ response = api.get_orders(
358
+ createdAfter: "2023-01-01T00:00:00Z",
359
+ limit: 10
360
+ )
361
+ response.parse["orders"]
362
+ ```
212
363
 
213
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_Overview.html)
214
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Recommendations/Client)
364
+ #### Vendor Direct Fulfillment Inventory API (2021-12-28)
215
365
 
216
- ### Reports
366
+ Enables vendors to update inventory levels for direct fulfillment items.
217
367
 
218
- The Reports API lets you request reports about your inventory and orders.
368
+ ```ruby
369
+ api = Peddler.vendor_direct_fulfillment_inventory_2021_12_28(aws_region, access_token)
370
+ response = api.submit_inventory_update(
371
+ body: {
372
+ inventory: [
373
+ {
374
+ sellingParty: {
375
+ partyId: "<PARTY_ID>"
376
+ },
377
+ warehouseId: "<WAREHOUSE_ID>",
378
+ items: [
379
+ {
380
+ buyerProductIdentifier: "B08N5WRWNW",
381
+ availableQuantity: {
382
+ amount: 100,
383
+ unitOfMeasure: "Each"
384
+ }
385
+ }
386
+ ]
387
+ }
388
+ ]
389
+ }
390
+ )
391
+ response.parse
392
+ ```
393
+
394
+ #### Shipping API (v2)
219
395
 
220
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/reports/Reports_Overview.html)
221
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Reports/Client)
396
+ Provides functionalities for purchasing shipping labels and tracking shipments.
397
+
398
+ ```ruby
399
+ api = Peddler.shipping_v2(aws_region, access_token)
400
+ response = api.purchase_shipment(
401
+ body: {
402
+ clientReferenceId: "CLIENT_REF_123",
403
+ shipTo: {
404
+ name: "John Doe",
405
+ addressLine1: "123 Main St",
406
+ city: "Anytown",
407
+ stateOrRegion: "NY",
408
+ postalCode: "12345",
409
+ countryCode: "US"
410
+ },
411
+ shipFrom: {
412
+ name: "Your Company",
413
+ addressLine1: "123 Warehouse Ave",
414
+ city: "Anytown",
415
+ stateOrRegion: "NY",
416
+ postalCode: "12345",
417
+ countryCode: "US"
418
+ },
419
+ packages: [
420
+ {
421
+ dimensions: {
422
+ length: 10,
423
+ width: 5,
424
+ height: 8,
425
+ unit: "IN"
426
+ },
427
+ weight: {
428
+ value: 2,
429
+ unit: "LB"
430
+ }
431
+ }
432
+ ],
433
+ serviceType: "Standard"
434
+ }
435
+ )
436
+ response.parse
437
+ ```
222
438
 
223
- ### Sellers
439
+ #### Token API (2021-03-01)
224
440
 
225
- The Sellers API lets sellers retrieve information about their seller account, such as the marketplaces they participate in.
441
+ Allows you to create restricted data tokens to access personally identifiable information (PII) in specific API calls.
226
442
 
227
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_Overview.html)
228
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Sellers/Client)
443
+ ```ruby
444
+ api = Peddler.tokens_2021_03_01(aws_region, access_token)
445
+ response = api.create_restricted_data_token(
446
+ body: {
447
+ restrictedResources: [
448
+ {
449
+ method: "GET",
450
+ path: "/orders/v0/orders/123-1234567-1234567",
451
+ dataElements: ["buyerInfo", "shippingAddress"]
452
+ }
453
+ ]
454
+ }
455
+ )
456
+ restricted_data_token = response.parse["restrictedDataToken"]
457
+
458
+ # Use the token in subsequent API calls
459
+ orders_api = Peddler.orders_2021_12_01("<AWS_REGION>", restricted_data_token)
460
+ response = orders_api.get_order(
461
+ orderId: "123-1234567-1234567"
462
+ )
463
+ response.parse
464
+ ```
229
465
 
230
- ### Shipment Invoicing
466
+ #### Finances API (v0)
231
467
 
232
- With the Shipment Invoicing API section (in conjunction with the FBAOutboundShipmentStatus notification), you can integrate invoicing into Amazon’s shipping process for a seller’s Fulfillment by Amazon (FBA) orders.
468
+ Provides information about financial events for your seller account, such as order payments, refunds, and fees.
233
469
 
234
- This functionality is available only in the Brazil marketplace.
470
+ ```ruby
471
+ api = Peddler.finances_v0(aws_region, access_token)
472
+ response = api.list_financial_events(
473
+ postedAfter: "2023-01-01T00:00:00Z",
474
+ maxResultsPerPage: 100
475
+ )
476
+ response.parse
477
+ ```
235
478
 
236
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_Overview.html)
237
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/ShipmentInvoicing/Client)
479
+ #### Sellers API (V1)
238
480
 
239
- ### Subscriptions
481
+ Provides information about seller's marketplaces and participation status.
240
482
 
241
- The Amazon MWS Subscriptions API section enables you to subscribe to receive notifications that are relevant to your business with Amazon. With the operations in the Subscriptions API section, you can register to receive important information from Amazon without having to poll the Amazon MWS service. Instead, the information is sent directly to you when an event occurs to which you are subscribed.
483
+ ```ruby
484
+ api = Peddler.sellers_v1(aws_region, access_token)
485
+ response = api.get_marketplace_participations
486
+ response.parse
487
+ ```
242
488
 
243
- - [Amazon references](https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_Overview.html)
244
- - [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Subscriptions/Client)
489
+ ## TODO
490
+
491
+ - Code generate models to parse payload. Consider using `dry-struct`.
492
+ - Code generate the APIs section—descriptions and code examples—in this README here.
493
+ - Schedule code generation with GitHub Actions. Push new gem when models change.
494
+ - Review and consider applying [these patches][patches].
495
+
496
+ [build]: https://github.com/hakanensari/peddler/actions
497
+ [maintainability]: https://codeclimate.com/github/hakanensari/peddler/maintainability
498
+ [test-coverage]: https://codeclimate.com/github/hakanensari/peddler/test_coverage
499
+ [docs-overview]: https://developer.amazonservices.com/sp-api-docs/overview
500
+ [register-as-developer]: https://developer-docs.amazon.com/sp-api/docs/registering-as-a-developer
501
+ [register-application]: https://developer-docs.amazon.com/sp-api/docs/registering-your-application
502
+ [view-credentials]: https://developer-docs.amazon.com/sp-api/docs/viewing-your-application-information-and-credentials
503
+ [authorization]: https://developer-docs.amazon.com/sp-api/docs/authorizing-selling-partner-api-applications
504
+ [rate-limits]: https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits
505
+ [httprb]: https://github.com/httprb/http
506
+ [patches]: https://github.com/bizon/selling-partner-api-sdk/tree/master/codegen/patches