python-amazon-sp-api 2.0.6__py3-none-any.whl → 2.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-amazon-sp-api
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: Python wrapper for the Amazon Selling-Partner API
5
5
  Home-page: https://github.com/saleweaver/python-amazon-sp-api
6
6
  Author: Michael Primke
@@ -1,7 +1,7 @@
1
- python_amazon_sp_api-2.0.6.data/scripts/make_endpoint,sha256=QWcwG6z4RWFJlzj4-xyHJymjObyKtwkvWFRq8T18iG0,8568
2
- python_amazon_sp_api-2.0.6.dist-info/licenses/LICENSE,sha256=nbzomPIVo1PVl5bpGAntofsYAF7ZQ2UhzOtKgf7IiNw,1071
1
+ python_amazon_sp_api-2.0.8.data/scripts/make_endpoint,sha256=QWcwG6z4RWFJlzj4-xyHJymjObyKtwkvWFRq8T18iG0,8568
2
+ python_amazon_sp_api-2.0.8.dist-info/licenses/LICENSE,sha256=nbzomPIVo1PVl5bpGAntofsYAF7ZQ2UhzOtKgf7IiNw,1071
3
3
  sp_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- sp_api/__version__.py,sha256=_rdDXO0eF8Rb-UlqwwfOrLeR0p4mNliGj-gv5nXgbms,22
4
+ sp_api/__version__.py,sha256=ImzYQIMT0WJBqsWPWEXvp24h0GJq6HfzSgGSEEuoxcs,22
5
5
  sp_api/api/__init__.py,sha256=QTDz2g_fryNGkGszhytqhI8K3x_ttP7fbXLJ5uRvmj0,4747
6
6
  sp_api/api/amazon_warehousing_and_distribu/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  sp_api/api/amazon_warehousing_and_distribu/amazon_warehousing_and_distribu.py,sha256=bMBIxIj0eu6Gi6WY3XLdHHYDzNCwz0-9X59Jo9DoqfE,5863
@@ -52,12 +52,12 @@ sp_api/api/notifications/notifications.py,sha256=VbMQcRHlrLuZqx252kDR9n0zX2FVcEU
52
52
  sp_api/api/orders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  sp_api/api/orders/orders.py,sha256=TIbhUVnrm1CE7Wobgz3uKmHBpynVmSKzQREshT5fpiw,13227
54
54
  sp_api/api/product_fees/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
- sp_api/api/product_fees/product_fees.py,sha256=M40hXGYUG1gs8FxH_EZUQPaihva-p7hyyzRCROqVghw,7784
55
+ sp_api/api/product_fees/product_fees.py,sha256=QwIVQKpXLXrc1Z2yQ2miSMizQsvprHVmxvG9vM_5niM,6913
56
56
  sp_api/api/product_type_definitions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  sp_api/api/product_type_definitions/product_type_definitions.py,sha256=sbQ4IurgxcXSJUTooX4KA8yu9e3EC0qq7Ax15T8lxcM,4472
58
58
  sp_api/api/products/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
59
  sp_api/api/products/products.py,sha256=xngNvsnILm011BT8HRM22XSqHzsX-iAuGqTUl0YCetE,16420
60
- sp_api/api/products/products_definitions.py,sha256=TVO1L-vjyzSmL54Xfa0m3K6rVUFaTNsYBjeGnLpscDI,5061
60
+ sp_api/api/products/products_definitions.py,sha256=bvnIrWmcR4ld_8YaqbwI18ht3B5V_NgClP4pzklF9Yg,341
61
61
  sp_api/api/replenishment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  sp_api/api/replenishment/replenishment.py,sha256=ehaeQSClepIk3jp7vaHwgVrWljryk-C0WIFKcweeb_8,7506
63
63
  sp_api/api/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -151,12 +151,12 @@ sp_api/asyncio/api/orders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
151
151
  sp_api/asyncio/api/orders/orders.py,sha256=IKns8nkkaYYSekquS6F_JAcLEGboecSXRWUqb0YBp7w,13358
152
152
  sp_api/asyncio/api/overrides/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
153
153
  sp_api/asyncio/api/product_fees/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
154
- sp_api/asyncio/api/product_fees/product_fees.py,sha256=dmIoMN8MrIJ9t5TbCRA9GMxkT6pXTPXWf7A_G0RiXPw,7876
154
+ sp_api/asyncio/api/product_fees/product_fees.py,sha256=9GIQuoz37_QDmKnCe9wdjyqAhX5-z1n_AaTdvVyt_N8,6998
155
155
  sp_api/asyncio/api/product_type_definitions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
156
156
  sp_api/asyncio/api/product_type_definitions/product_type_definitions.py,sha256=ncXLOEHo62bj4GWuMFEKe3IOv0F5i-VnaGsVA6EWK_Q,4552
157
157
  sp_api/asyncio/api/products/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
158
158
  sp_api/asyncio/api/products/products.py,sha256=6bDiSvhzio0do2yRnMppUB7c5FbmRDy2suhcquctDK0,16585
159
- sp_api/asyncio/api/products/products_definitions.py,sha256=EAX4g6CLtypocL-Hwpt-GlQUVWjmUTFpquJBGEZ8X9M,5108
159
+ sp_api/asyncio/api/products/products_definitions.py,sha256=bvnIrWmcR4ld_8YaqbwI18ht3B5V_NgClP4pzklF9Yg,341
160
160
  sp_api/asyncio/api/replenishment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  sp_api/asyncio/api/replenishment/replenishment.py,sha256=wFhkCmRKcyY3CCHiIacGrQUfZAKozIupgNMS_CvS-Wk,7598
162
162
  sp_api/asyncio/api/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -236,14 +236,16 @@ sp_api/base/reportTypes.py,sha256=26ZjqGlaSD6s3DDHlicvscuh6z7NBw9qQWSE5nVHhNQ,10
236
236
  sp_api/base/report_status.py,sha256=mHPPFvK2xpfucCl6Vk87BHFJO8FB1x0Ej-h3fQFOetE,179
237
237
  sp_api/base/sales_enum.py,sha256=O08knipDvuPEBYPM3kYEofl7t6uGZ-nJrn0L9q3CX9w,395
238
238
  sp_api/base/schedules.py,sha256=WX0tYSAK4kI-ceBqeE_cY2_MaKC2usEgV2FDqujioqI,433
239
- sp_api/util/__init__.py,sha256=m2UYwlfumOl1vmKSHbMIrmgC_XNZ_PsMrMVlf5XCx_U,692
239
+ sp_api/util/__init__.py,sha256=_Kl02VHEvLih6A4LwUhYvv_qh5AK5uPsNtmkeKxVLtk,1332
240
240
  sp_api/util/key_maker.py,sha256=T4I2rdBZzvWtX32qgrv9DA5EzVK3LEAWtbRffup-_kE,2172
241
241
  sp_api/util/load_all_pages.py,sha256=K6Suml4_GWZ5L9-YcnhaM9q-dA7Xr6wNLE-kWP_8MPk,1839
242
242
  sp_api/util/load_date_bound.py,sha256=j9gu9WucENqU9xaQ-xG7c4yK4RB-FXK39_r1mLT76z0,1726
243
243
  sp_api/util/params.py,sha256=wXM5LgwB0EjA2T5guVjsdZUXHaXwB401cbXzH6B_GOE,1526
244
+ sp_api/util/product_fees.py,sha256=uvTct-armJYwkRsDn_2PBNOAD2H3_mfc8NqkFpjXzi4,1118
245
+ sp_api/util/products_definitions.py,sha256=TVO1L-vjyzSmL54Xfa0m3K6rVUFaTNsYBjeGnLpscDI,5061
244
246
  sp_api/util/report_document.py,sha256=_LxuIJDIb6DTvzobY4qdlQ78ibZi6rwQ1dDK3FMxegs,4682
245
247
  sp_api/util/retry.py,sha256=V8SeSeX3Brdou138hNA5HeQkKlHppZcqbZobIDjmBYw,2407
246
- python_amazon_sp_api-2.0.6.dist-info/METADATA,sha256=-7iomKmftWrYVVrL9uJt-AiE6UFUtg3AGboo4O2V2bY,6968
247
- python_amazon_sp_api-2.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
248
- python_amazon_sp_api-2.0.6.dist-info/top_level.txt,sha256=mEzPMFyyy0LmJGY4KFXfh5usUka4eeouIr7-2IAzoE0,7
249
- python_amazon_sp_api-2.0.6.dist-info/RECORD,,
248
+ python_amazon_sp_api-2.0.8.dist-info/METADATA,sha256=h5tpCRSX6JomF93bou26MEXOnTUOZCS3-_LhS6lntGE,6968
249
+ python_amazon_sp_api-2.0.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
250
+ python_amazon_sp_api-2.0.8.dist-info/top_level.txt,sha256=mEzPMFyyy0LmJGY4KFXfh5usUka4eeouIr7-2IAzoE0,7
251
+ python_amazon_sp_api-2.0.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
sp_api/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '2.0.6'
1
+ __version__ = '2.0.8'
@@ -3,6 +3,7 @@ from urllib.parse import quote_plus
3
3
 
4
4
  from sp_api.base.helpers import sp_endpoint, fill_query_params
5
5
  from sp_api.base import Client, ApiResponse
6
+ from sp_api.util.product_fees import create_fees_body
6
7
 
7
8
 
8
9
  class ProductFees(Client):
@@ -63,15 +64,15 @@ class ProductFees(Client):
63
64
  seller_sku = quote_plus(seller_sku)
64
65
 
65
66
  kwargs.update(
66
- self._create_body(
67
- price,
68
- shipping_price,
69
- currency,
70
- is_fba,
71
- seller_sku,
72
- points,
73
- marketplace_id,
74
- optional_fulfillment_program,
67
+ create_fees_body(
68
+ price=price,
69
+ shipping_price=shipping_price,
70
+ currency=currency,
71
+ is_fba=is_fba,
72
+ identifier=seller_sku,
73
+ points=points,
74
+ marketplace_id=marketplace_id or self.marketplace_id,
75
+ optional_fulfillment_program=optional_fulfillment_program,
75
76
  )
76
77
  )
77
78
  return self._request(
@@ -124,15 +125,15 @@ class ProductFees(Client):
124
125
 
125
126
  """
126
127
  kwargs.update(
127
- self._create_body(
128
- price,
129
- shipping_price,
130
- currency,
131
- is_fba,
132
- asin,
133
- points,
134
- marketplace_id,
135
- optional_fulfillment_program,
128
+ create_fees_body(
129
+ price=price,
130
+ shipping_price=shipping_price,
131
+ currency=currency,
132
+ is_fba=is_fba,
133
+ identifier=asin,
134
+ points=points,
135
+ marketplace_id=marketplace_id or self.marketplace_id,
136
+ optional_fulfillment_program=optional_fulfillment_program,
136
137
  )
137
138
  )
138
139
  return self._request(fill_query_params(kwargs.pop("path"), asin), data=kwargs)
@@ -166,7 +167,18 @@ class ProductFees(Client):
166
167
  marketplace_id: str | Defaults to self.marketplace_id
167
168
  optional_fulfillment_program:
168
169
  """
169
- data = [dict(**self._create_body(**er)) for er in estimate_requests]
170
+ data = []
171
+ for estimate in estimate_requests:
172
+ estimate_payload = dict(estimate)
173
+ marketplace_id = estimate_payload.pop("marketplace_id", None)
174
+ data.append(
175
+ dict(
176
+ **create_fees_body(
177
+ marketplace_id=marketplace_id or self.marketplace_id,
178
+ **estimate_payload,
179
+ )
180
+ )
181
+ )
170
182
  return self._request(
171
183
  "/products/fees/v0/feesEstimate",
172
184
  data=data,
@@ -174,61 +186,6 @@ class ProductFees(Client):
174
186
  wrap_list=True,
175
187
  )
176
188
 
177
- def _create_body(
178
- self,
179
- price,
180
- shipping_price=None,
181
- currency="USD",
182
- is_fba=False,
183
- identifier=None,
184
- points: dict = None,
185
- marketplace_id: str = None,
186
- optional_fulfillment_program: str = None,
187
- id_type=None,
188
- id_value=None,
189
- ):
190
- """
191
- Create request body
192
-
193
- Args:
194
- price:
195
- shipping_price:
196
- currency:
197
- is_fba:
198
- identifier:
199
- points:
200
-
201
- Returns:
202
-
203
- """
204
- body = {
205
- "FeesEstimateRequest": {
206
- "Identifier": identifier or str(price),
207
- "PriceToEstimateFees": {
208
- "ListingPrice": {"Amount": price, "CurrencyCode": currency},
209
- "Shipping": (
210
- {"Amount": shipping_price, "CurrencyCode": currency}
211
- if shipping_price
212
- else None
213
- ),
214
- "Points": points or None,
215
- },
216
- "IsAmazonFulfilled": is_fba,
217
- "OptionalFulfillmentProgram": (
218
- optional_fulfillment_program
219
- if is_fba is True and optional_fulfillment_program
220
- else None
221
- ),
222
- "MarketplaceId": marketplace_id or self.marketplace_id,
223
- }
224
- }
225
-
226
- if id_type and id_value:
227
- body["IdType"] = id_type
228
- body["IdValue"] = id_value
229
-
230
- return body
231
-
232
189
  def _add_marketplaces(self, data):
233
190
  # MarketplaceID is a property of the body's FeesEstimateRequest for this section, and does
234
191
  # not need to be added. Additionally, Client._add_marketplaces will fail as it assumes
@@ -1,169 +1,11 @@
1
- from enum import Enum
2
- from typing import Optional, List, Dict, Union
3
- from dataclasses import dataclass, asdict
4
-
5
-
6
- class CompetitiveSummaryIncludedData(Enum):
7
- FEATURED_BUYING_OPTIONS = "featuredBuyingOptions"
8
- LOWEST_PRICED_OFFERS = "lowestPricedOffers"
9
- REFERENCE_PRICES = "referencePrices"
10
-
11
-
12
- @dataclass
13
- class ItemOffersRequest:
14
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
15
- #itemoffersrequest"""
16
-
17
- uri: str
18
- method: str
19
- MarketplaceId: str
20
- ItemCondition: str = None
21
- CustomerType: str = None
22
- headers: Dict = None
23
-
24
-
25
- @dataclass
26
- class GetItemOffersBatchRequest:
27
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
28
- #getitemoffersbatchrequest"""
29
-
30
- requests: Optional[List[Union[ItemOffersRequest, Dict]]] = None
31
-
32
- def __post_init__(self):
33
- self.requests = self.parse_requests(self.requests)
34
-
35
- def to_dict(self):
36
- return asdict(self)
37
-
38
- @staticmethod
39
- def parse_requests(requests) -> List[ItemOffersRequest]:
40
- parsed_requestes = []
41
-
42
- for request in requests:
43
- if isinstance(request, Dict):
44
- request = ItemOffersRequest(**request)
45
-
46
- if not isinstance(request, ItemOffersRequest):
47
- raise TypeError
48
-
49
- parsed_requestes.append(request)
50
-
51
- return parsed_requestes
52
-
53
-
54
- @dataclass
55
- class ListingOffersRequest:
56
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
57
- #listingoffersrequest"""
58
-
59
- uri: str
60
- MarketplaceId: str
61
- ItemCondition: str
62
- method: str = "GET"
63
- CustomerType: str = "Consumer"
64
-
65
-
66
- @dataclass
67
- class GetListingOffersBatchRequest:
68
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
69
- #getlistingoffersbatchrequest"""
70
-
71
- requests: Optional[List[Union[ListingOffersRequest, Dict]]] = None
72
-
73
- def __post_init__(self):
74
- self.requests = self.parse_requests(self.requests)
75
-
76
- def to_dict(self):
77
- return asdict(self)
78
-
79
- @staticmethod
80
- def parse_requests(requests) -> List[ListingOffersRequest]:
81
- parsed_requestes = []
82
-
83
- for request in requests:
84
- if isinstance(request, Dict):
85
- request = ListingOffersRequest(**request)
86
-
87
- if not isinstance(request, ListingOffersRequest):
88
- raise TypeError
89
-
90
- parsed_requestes.append(request)
91
-
92
- return parsed_requestes
93
-
94
-
95
- @dataclass
96
- class FeaturedOfferExpectedPriceRequest:
97
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
98
- #FeaturedOfferExpectedPriceRequest """
99
- marketplaceId: str
100
- sku: str
101
- uri: str = "/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice"
102
- method: str = "GET"
103
-
104
-
105
- @dataclass
106
- class GetFeaturedOfferExpectedPriceBatch:
107
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
108
- #getFeaturedOfferExpectedPriceBatch """
109
- requests: Optional[List[Union[FeaturedOfferExpectedPriceRequest, Dict]]] = None
110
-
111
- def __post_init__(self):
112
- self.requests = self.parse_requests(self.requests)
113
-
114
- def to_dict(self):
115
- return asdict(self)
116
-
117
- @staticmethod
118
- def parse_requests(requests) -> List[FeaturedOfferExpectedPriceRequest]:
119
- parsed_requests = []
120
-
121
- for request in requests:
122
- if isinstance(request, Dict):
123
- request = FeaturedOfferExpectedPriceRequest(**request)
124
-
125
- if not isinstance(request, FeaturedOfferExpectedPriceRequest):
126
- raise TypeError
127
-
128
- parsed_requests.append(request)
129
-
130
- return parsed_requests
131
-
132
-
133
- @dataclass
134
- class CompetitiveSummaryRequest:
135
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
136
- #FeaturedOfferExpectedPriceRequest """
137
- marketplaceId: str
138
- asin: str
139
- includedData: List[CompetitiveSummaryIncludedData]
140
- uri: str = "/products/pricing/2022-05-01/items/competitiveSummary"
141
- method: str = "GET"
142
-
143
-
144
- @dataclass
145
- class GetCompetitiveSummaryBatch:
146
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
147
- #getCompetitiveSummary """
148
- requests: Optional[List[Union[CompetitiveSummaryRequest, Dict]]] = None
149
-
150
- def __post_init__(self):
151
- self.requests = self.parse_requests(self.requests)
152
-
153
- def to_dict(self):
154
- return asdict(self)
155
-
156
- @staticmethod
157
- def parse_requests(requests) -> List[CompetitiveSummaryRequest]:
158
- parsed_requests = []
159
-
160
- for request in requests:
161
- if isinstance(request, Dict):
162
- request = CompetitiveSummaryRequest(**request)
163
-
164
- if not isinstance(request, CompetitiveSummaryRequest):
165
- raise TypeError
166
-
167
- parsed_requests.append(request)
168
-
169
- return parsed_requests
1
+ from sp_api.util.products_definitions import (
2
+ CompetitiveSummaryIncludedData,
3
+ ItemOffersRequest,
4
+ GetItemOffersBatchRequest,
5
+ ListingOffersRequest,
6
+ GetListingOffersBatchRequest,
7
+ FeaturedOfferExpectedPriceRequest,
8
+ GetFeaturedOfferExpectedPriceBatch,
9
+ CompetitiveSummaryRequest,
10
+ GetCompetitiveSummaryBatch,
11
+ )
@@ -2,8 +2,9 @@ from typing import List
2
2
  from urllib.parse import quote_plus
3
3
 
4
4
  from sp_api.base.helpers import sp_endpoint, fill_query_params
5
- from sp_api.base import Client, ApiResponse
5
+ from sp_api.base import ApiResponse
6
6
  from sp_api.asyncio.base import AsyncBaseClient
7
+ from sp_api.util.product_fees import create_fees_body
7
8
 
8
9
 
9
10
  class ProductFees(AsyncBaseClient):
@@ -64,15 +65,15 @@ class ProductFees(AsyncBaseClient):
64
65
  seller_sku = quote_plus(seller_sku)
65
66
 
66
67
  kwargs.update(
67
- self._create_body(
68
- price,
69
- shipping_price,
70
- currency,
71
- is_fba,
72
- seller_sku,
73
- points,
74
- marketplace_id,
75
- optional_fulfillment_program,
68
+ create_fees_body(
69
+ price=price,
70
+ shipping_price=shipping_price,
71
+ currency=currency,
72
+ is_fba=is_fba,
73
+ identifier=seller_sku,
74
+ points=points,
75
+ marketplace_id=marketplace_id or self.marketplace_id,
76
+ optional_fulfillment_program=optional_fulfillment_program,
76
77
  )
77
78
  )
78
79
  return await self._request(
@@ -125,15 +126,15 @@ class ProductFees(AsyncBaseClient):
125
126
 
126
127
  """
127
128
  kwargs.update(
128
- self._create_body(
129
- price,
130
- shipping_price,
131
- currency,
132
- is_fba,
133
- asin,
134
- points,
135
- marketplace_id,
136
- optional_fulfillment_program,
129
+ create_fees_body(
130
+ price=price,
131
+ shipping_price=shipping_price,
132
+ currency=currency,
133
+ is_fba=is_fba,
134
+ identifier=asin,
135
+ points=points,
136
+ marketplace_id=marketplace_id or self.marketplace_id,
137
+ optional_fulfillment_program=optional_fulfillment_program,
137
138
  )
138
139
  )
139
140
  return await self._request(fill_query_params(kwargs.pop("path"), asin), data=kwargs)
@@ -167,7 +168,18 @@ class ProductFees(AsyncBaseClient):
167
168
  marketplace_id: str | Defaults to self.marketplace_id
168
169
  optional_fulfillment_program:
169
170
  """
170
- data = [dict(**self._create_body(**er)) for er in estimate_requests]
171
+ data = []
172
+ for estimate in estimate_requests:
173
+ estimate_payload = dict(estimate)
174
+ marketplace_id = estimate_payload.pop("marketplace_id", None)
175
+ data.append(
176
+ dict(
177
+ **create_fees_body(
178
+ marketplace_id=marketplace_id or self.marketplace_id,
179
+ **estimate_payload,
180
+ )
181
+ )
182
+ )
171
183
  return await self._request(
172
184
  "/products/fees/v0/feesEstimate",
173
185
  data=data,
@@ -175,63 +187,8 @@ class ProductFees(AsyncBaseClient):
175
187
  wrap_list=True,
176
188
  )
177
189
 
178
- def _create_body(
179
- self,
180
- price,
181
- shipping_price=None,
182
- currency="USD",
183
- is_fba=False,
184
- identifier=None,
185
- points: dict = None,
186
- marketplace_id: str = None,
187
- optional_fulfillment_program: str = None,
188
- id_type=None,
189
- id_value=None,
190
- ):
191
- """
192
- Create request body
193
-
194
- Args:
195
- price:
196
- shipping_price:
197
- currency:
198
- is_fba:
199
- identifier:
200
- points:
201
-
202
- Returns:
203
-
204
- """
205
- body = {
206
- "FeesEstimateRequest": {
207
- "Identifier": identifier or str(price),
208
- "PriceToEstimateFees": {
209
- "ListingPrice": {"Amount": price, "CurrencyCode": currency},
210
- "Shipping": (
211
- {"Amount": shipping_price, "CurrencyCode": currency}
212
- if shipping_price
213
- else None
214
- ),
215
- "Points": points or None,
216
- },
217
- "IsAmazonFulfilled": is_fba,
218
- "OptionalFulfillmentProgram": (
219
- optional_fulfillment_program
220
- if is_fba is True and optional_fulfillment_program
221
- else None
222
- ),
223
- "MarketplaceId": marketplace_id or self.marketplace_id,
224
- }
225
- }
226
-
227
- if id_type and id_value:
228
- body["IdType"] = id_type
229
- body["IdValue"] = id_value
230
-
231
- return body
232
-
233
190
  def _add_marketplaces(self, data):
234
191
  # MarketplaceID is a property of the body's FeesEstimateRequest for this section, and does
235
192
  # not need to be added. Additionally, Client._add_marketplaces will fail as it assumes
236
193
  # data is a dict, which is not the case for get_product_fees_estimate.
237
- pass
194
+ pass
@@ -1,170 +1,11 @@
1
- from sp_api.asyncio.base import AsyncBaseClient
2
- from enum import Enum
3
- from typing import Optional, List, Dict, Union
4
- from dataclasses import dataclass, asdict
5
-
6
-
7
- class CompetitiveSummaryIncludedData(Enum):
8
- FEATURED_BUYING_OPTIONS = "featuredBuyingOptions"
9
- LOWEST_PRICED_OFFERS = "lowestPricedOffers"
10
- REFERENCE_PRICES = "referencePrices"
11
-
12
-
13
- @dataclass
14
- class ItemOffersRequest:
15
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
16
- #itemoffersrequest"""
17
-
18
- uri: str
19
- method: str
20
- MarketplaceId: str
21
- ItemCondition: str = None
22
- CustomerType: str = None
23
- headers: Dict = None
24
-
25
-
26
- @dataclass
27
- class GetItemOffersBatchRequest:
28
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
29
- #getitemoffersbatchrequest"""
30
-
31
- requests: Optional[List[Union[ItemOffersRequest, Dict]]] = None
32
-
33
- def __post_init__(self):
34
- self.requests = self.parse_requests(self.requests)
35
-
36
- def to_dict(self):
37
- return asdict(self)
38
-
39
- @staticmethod
40
- def parse_requests(requests) -> List[ItemOffersRequest]:
41
- parsed_requestes = []
42
-
43
- for request in requests:
44
- if isinstance(request, Dict):
45
- request = ItemOffersRequest(**request)
46
-
47
- if not isinstance(request, ItemOffersRequest):
48
- raise TypeError
49
-
50
- parsed_requestes.append(request)
51
-
52
- return parsed_requestes
53
-
54
-
55
- @dataclass
56
- class ListingOffersRequest:
57
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
58
- #listingoffersrequest"""
59
-
60
- uri: str
61
- MarketplaceId: str
62
- ItemCondition: str
63
- method: str = "GET"
64
- CustomerType: str = "Consumer"
65
-
66
-
67
- @dataclass
68
- class GetListingOffersBatchRequest:
69
- """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
70
- #getlistingoffersbatchrequest"""
71
-
72
- requests: Optional[List[Union[ListingOffersRequest, Dict]]] = None
73
-
74
- def __post_init__(self):
75
- self.requests = self.parse_requests(self.requests)
76
-
77
- def to_dict(self):
78
- return asdict(self)
79
-
80
- @staticmethod
81
- def parse_requests(requests) -> List[ListingOffersRequest]:
82
- parsed_requestes = []
83
-
84
- for request in requests:
85
- if isinstance(request, Dict):
86
- request = ListingOffersRequest(**request)
87
-
88
- if not isinstance(request, ListingOffersRequest):
89
- raise TypeError
90
-
91
- parsed_requestes.append(request)
92
-
93
- return parsed_requestes
94
-
95
-
96
- @dataclass
97
- class FeaturedOfferExpectedPriceRequest:
98
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
99
- #FeaturedOfferExpectedPriceRequest """
100
- marketplaceId: str
101
- sku: str
102
- uri: str = "/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice"
103
- method: str = "GET"
104
-
105
-
106
- @dataclass
107
- class GetFeaturedOfferExpectedPriceBatch:
108
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
109
- #getFeaturedOfferExpectedPriceBatch """
110
- requests: Optional[List[Union[FeaturedOfferExpectedPriceRequest, Dict]]] = None
111
-
112
- def __post_init__(self):
113
- self.requests = self.parse_requests(self.requests)
114
-
115
- def to_dict(self):
116
- return asdict(self)
117
-
118
- @staticmethod
119
- def parse_requests(requests) -> List[FeaturedOfferExpectedPriceRequest]:
120
- parsed_requests = []
121
-
122
- for request in requests:
123
- if isinstance(request, Dict):
124
- request = FeaturedOfferExpectedPriceRequest(**request)
125
-
126
- if not isinstance(request, FeaturedOfferExpectedPriceRequest):
127
- raise TypeError
128
-
129
- parsed_requests.append(request)
130
-
131
- return parsed_requests
132
-
133
-
134
- @dataclass
135
- class CompetitiveSummaryRequest:
136
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
137
- #FeaturedOfferExpectedPriceRequest """
138
- marketplaceId: str
139
- asin: str
140
- includedData: List[CompetitiveSummaryIncludedData]
141
- uri: str = "/products/pricing/2022-05-01/items/competitiveSummary"
142
- method: str = "GET"
143
-
144
-
145
- @dataclass
146
- class GetCompetitiveSummaryBatch:
147
- """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
148
- #getCompetitiveSummary """
149
- requests: Optional[List[Union[CompetitiveSummaryRequest, Dict]]] = None
150
-
151
- def __post_init__(self):
152
- self.requests = self.parse_requests(self.requests)
153
-
154
- def to_dict(self):
155
- return asdict(self)
156
-
157
- @staticmethod
158
- def parse_requests(requests) -> List[CompetitiveSummaryRequest]:
159
- parsed_requests = []
160
-
161
- for request in requests:
162
- if isinstance(request, Dict):
163
- request = CompetitiveSummaryRequest(**request)
164
-
165
- if not isinstance(request, CompetitiveSummaryRequest):
166
- raise TypeError
167
-
168
- parsed_requests.append(request)
169
-
170
- return parsed_requests
1
+ from sp_api.util.products_definitions import (
2
+ CompetitiveSummaryIncludedData,
3
+ ItemOffersRequest,
4
+ GetItemOffersBatchRequest,
5
+ ListingOffersRequest,
6
+ GetListingOffersBatchRequest,
7
+ FeaturedOfferExpectedPriceRequest,
8
+ GetFeaturedOfferExpectedPriceBatch,
9
+ CompetitiveSummaryRequest,
10
+ GetCompetitiveSummaryBatch,
11
+ )
sp_api/util/__init__.py CHANGED
@@ -11,6 +11,17 @@ from .params import (
11
11
  should_add_marketplace,
12
12
  ensure_csv,
13
13
  )
14
+ from .products_definitions import (
15
+ CompetitiveSummaryIncludedData,
16
+ ItemOffersRequest,
17
+ GetItemOffersBatchRequest,
18
+ ListingOffersRequest,
19
+ GetListingOffersBatchRequest,
20
+ FeaturedOfferExpectedPriceRequest,
21
+ GetFeaturedOfferExpectedPriceBatch,
22
+ CompetitiveSummaryRequest,
23
+ GetCompetitiveSummaryBatch,
24
+ )
14
25
 
15
26
  __all__ = [
16
27
  "retry",
@@ -26,4 +37,13 @@ __all__ = [
26
37
  "encode_kwarg",
27
38
  "should_add_marketplace",
28
39
  "ensure_csv",
40
+ "CompetitiveSummaryIncludedData",
41
+ "ItemOffersRequest",
42
+ "GetItemOffersBatchRequest",
43
+ "ListingOffersRequest",
44
+ "GetListingOffersBatchRequest",
45
+ "FeaturedOfferExpectedPriceRequest",
46
+ "GetFeaturedOfferExpectedPriceBatch",
47
+ "CompetitiveSummaryRequest",
48
+ "GetCompetitiveSummaryBatch",
29
49
  ]
@@ -0,0 +1,40 @@
1
+ def create_fees_body(
2
+ *,
3
+ price,
4
+ shipping_price=None,
5
+ currency="USD",
6
+ is_fba=False,
7
+ identifier=None,
8
+ points=None,
9
+ marketplace_id=None,
10
+ optional_fulfillment_program=None,
11
+ id_type=None,
12
+ id_value=None,
13
+ ):
14
+ body = {
15
+ "FeesEstimateRequest": {
16
+ "Identifier": identifier or str(price),
17
+ "PriceToEstimateFees": {
18
+ "ListingPrice": {"Amount": price, "CurrencyCode": currency},
19
+ "Shipping": (
20
+ {"Amount": shipping_price, "CurrencyCode": currency}
21
+ if shipping_price
22
+ else None
23
+ ),
24
+ "Points": points or None,
25
+ },
26
+ "IsAmazonFulfilled": is_fba,
27
+ "OptionalFulfillmentProgram": (
28
+ optional_fulfillment_program
29
+ if is_fba is True and optional_fulfillment_program
30
+ else None
31
+ ),
32
+ "MarketplaceId": marketplace_id,
33
+ }
34
+ }
35
+
36
+ if id_type and id_value:
37
+ body["IdType"] = id_type
38
+ body["IdValue"] = id_value
39
+
40
+ return body
@@ -0,0 +1,169 @@
1
+ from enum import Enum
2
+ from typing import Optional, List, Dict, Union
3
+ from dataclasses import dataclass, asdict
4
+
5
+
6
+ class CompetitiveSummaryIncludedData(Enum):
7
+ FEATURED_BUYING_OPTIONS = "featuredBuyingOptions"
8
+ LOWEST_PRICED_OFFERS = "lowestPricedOffers"
9
+ REFERENCE_PRICES = "referencePrices"
10
+
11
+
12
+ @dataclass
13
+ class ItemOffersRequest:
14
+ """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
15
+ #itemoffersrequest"""
16
+
17
+ uri: str
18
+ method: str
19
+ MarketplaceId: str
20
+ ItemCondition: str = None
21
+ CustomerType: str = None
22
+ headers: Dict = None
23
+
24
+
25
+ @dataclass
26
+ class GetItemOffersBatchRequest:
27
+ """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
28
+ #getitemoffersbatchrequest"""
29
+
30
+ requests: Optional[List[Union[ItemOffersRequest, Dict]]] = None
31
+
32
+ def __post_init__(self):
33
+ self.requests = self.parse_requests(self.requests)
34
+
35
+ def to_dict(self):
36
+ return asdict(self)
37
+
38
+ @staticmethod
39
+ def parse_requests(requests) -> List[ItemOffersRequest]:
40
+ parsed_requestes = []
41
+
42
+ for request in requests:
43
+ if isinstance(request, Dict):
44
+ request = ItemOffersRequest(**request)
45
+
46
+ if not isinstance(request, ItemOffersRequest):
47
+ raise TypeError
48
+
49
+ parsed_requestes.append(request)
50
+
51
+ return parsed_requestes
52
+
53
+
54
+ @dataclass
55
+ class ListingOffersRequest:
56
+ """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
57
+ #listingoffersrequest"""
58
+
59
+ uri: str
60
+ MarketplaceId: str
61
+ ItemCondition: str
62
+ method: str = "GET"
63
+ CustomerType: str = "Consumer"
64
+
65
+
66
+ @dataclass
67
+ class GetListingOffersBatchRequest:
68
+ """Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v0-reference
69
+ #getlistingoffersbatchrequest"""
70
+
71
+ requests: Optional[List[Union[ListingOffersRequest, Dict]]] = None
72
+
73
+ def __post_init__(self):
74
+ self.requests = self.parse_requests(self.requests)
75
+
76
+ def to_dict(self):
77
+ return asdict(self)
78
+
79
+ @staticmethod
80
+ def parse_requests(requests) -> List[ListingOffersRequest]:
81
+ parsed_requestes = []
82
+
83
+ for request in requests:
84
+ if isinstance(request, Dict):
85
+ request = ListingOffersRequest(**request)
86
+
87
+ if not isinstance(request, ListingOffersRequest):
88
+ raise TypeError
89
+
90
+ parsed_requestes.append(request)
91
+
92
+ return parsed_requestes
93
+
94
+
95
+ @dataclass
96
+ class FeaturedOfferExpectedPriceRequest:
97
+ """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
98
+ #FeaturedOfferExpectedPriceRequest """
99
+ marketplaceId: str
100
+ sku: str
101
+ uri: str = "/products/pricing/2022-05-01/offer/featuredOfferExpectedPrice"
102
+ method: str = "GET"
103
+
104
+
105
+ @dataclass
106
+ class GetFeaturedOfferExpectedPriceBatch:
107
+ """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
108
+ #getFeaturedOfferExpectedPriceBatch """
109
+ requests: Optional[List[Union[FeaturedOfferExpectedPriceRequest, Dict]]] = None
110
+
111
+ def __post_init__(self):
112
+ self.requests = self.parse_requests(self.requests)
113
+
114
+ def to_dict(self):
115
+ return asdict(self)
116
+
117
+ @staticmethod
118
+ def parse_requests(requests) -> List[FeaturedOfferExpectedPriceRequest]:
119
+ parsed_requests = []
120
+
121
+ for request in requests:
122
+ if isinstance(request, Dict):
123
+ request = FeaturedOfferExpectedPriceRequest(**request)
124
+
125
+ if not isinstance(request, FeaturedOfferExpectedPriceRequest):
126
+ raise TypeError
127
+
128
+ parsed_requests.append(request)
129
+
130
+ return parsed_requests
131
+
132
+
133
+ @dataclass
134
+ class CompetitiveSummaryRequest:
135
+ """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
136
+ #FeaturedOfferExpectedPriceRequest """
137
+ marketplaceId: str
138
+ asin: str
139
+ includedData: List[CompetitiveSummaryIncludedData]
140
+ uri: str = "/products/pricing/2022-05-01/items/competitiveSummary"
141
+ method: str = "GET"
142
+
143
+
144
+ @dataclass
145
+ class GetCompetitiveSummaryBatch:
146
+ """ Implements definition: https://developer-docs.amazon.com/sp-api/docs/product-pricing-api-v2022-05-01-reference
147
+ #getCompetitiveSummary """
148
+ requests: Optional[List[Union[CompetitiveSummaryRequest, Dict]]] = None
149
+
150
+ def __post_init__(self):
151
+ self.requests = self.parse_requests(self.requests)
152
+
153
+ def to_dict(self):
154
+ return asdict(self)
155
+
156
+ @staticmethod
157
+ def parse_requests(requests) -> List[CompetitiveSummaryRequest]:
158
+ parsed_requests = []
159
+
160
+ for request in requests:
161
+ if isinstance(request, Dict):
162
+ request = CompetitiveSummaryRequest(**request)
163
+
164
+ if not isinstance(request, CompetitiveSummaryRequest):
165
+ raise TypeError
166
+
167
+ parsed_requests.append(request)
168
+
169
+ return parsed_requests