python-amazon-sp-api 2.0.9__py3-none-any.whl → 2.0.11__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.
@@ -0,0 +1,361 @@
1
+ from sp_api.asyncio.base import AsyncBaseClient
2
+ from sp_api.base import sp_endpoint, fill_query_params, ApiResponse
3
+ from sp_api.util import normalize_csv_param
4
+
5
+
6
+
7
+ class OrdersV0(AsyncBaseClient):
8
+
9
+ @sp_endpoint("/orders/v0/orders")
10
+ async def get_orders(self, **kwargs) -> ApiResponse:
11
+ """
12
+ get_orders(self, **kwargs) -> ApiResponse
13
+ Returns orders created or updated during the time frame indicated by the specified parameters.
14
+ You can also apply a range of filtering criteria to narrow the list of orders returned.
15
+ If NextToken is present, that will be used to retrieve the orders instead of other criteria.
16
+
17
+ **Usage Plan:**
18
+
19
+ ====================================== ==============
20
+ Rate (requests per second) Burst
21
+ ====================================== ==============
22
+ 1 1
23
+ ====================================== ==============
24
+
25
+
26
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
27
+
28
+ Examples:
29
+ literal blocks::
30
+
31
+ Orders().get_orders(CreatedAfter='TEST_CASE_200', MarketplaceIds=["ATVPDKIKX0DER"])
32
+
33
+ Args:
34
+ key CreatedAfter: date
35
+ key CreatedBefore: date
36
+ key LastUpdatedAfter: date
37
+ key LastUpdatedBefore: date
38
+ key OrderStatuses: [str]
39
+ key MarketplaceIds: [str]
40
+ key FulfillmentChannels: [str]
41
+ key PaymentMethods: [str]
42
+ key BuyerEmail: str
43
+ key SellerOrderId: str
44
+ key MaxResultsPerPage: int
45
+ key EasyShipShipmentStatuses: [str]
46
+ key NextToken: str
47
+ key AmazonOrderIds: [str]
48
+ key RestrictedResources: [str]
49
+
50
+ Returns:
51
+ ApiResponse:
52
+
53
+
54
+ """
55
+ normalize_csv_param(kwargs, "OrderStatuses")
56
+ normalize_csv_param(kwargs, "MarketplaceIds")
57
+ normalize_csv_param(kwargs, "FulfillmentChannels")
58
+ normalize_csv_param(kwargs, "PaymentMethods")
59
+ normalize_csv_param(kwargs, "AmazonOrderIds")
60
+
61
+ if "RestrictedResources" in kwargs:
62
+ return self._access_restricted(kwargs)
63
+ return await self._request(kwargs.pop("path"), params={**kwargs})
64
+
65
+ @sp_endpoint("/orders/v0/orders/{}")
66
+ async def get_order(self, order_id: str, **kwargs) -> ApiResponse:
67
+ """
68
+ get_order(self, order_id: str, **kwargs) -> ApiResponse
69
+ Returns the order indicated by the specified order ID.
70
+
71
+ **Usage Plan:**
72
+
73
+ ====================================== ==============
74
+ Rate (requests per second) Burst
75
+ ====================================== ==============
76
+ 1 1
77
+ ====================================== ==============
78
+
79
+
80
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
81
+
82
+ Examples:
83
+ literal blocks::
84
+
85
+ Orders().get_order('TEST_CASE_200')
86
+
87
+ Args:
88
+ order_id: str
89
+ key RestrictedResources: [str]
90
+ **kwargs:
91
+
92
+ Returns:
93
+ ApiResponse:
94
+
95
+
96
+ """
97
+ if "RestrictedResources" in kwargs:
98
+ kwargs.update(
99
+ {"original_path": fill_query_params(kwargs.get("path"), order_id)}
100
+ )
101
+ return self._access_restricted(kwargs)
102
+ return await self._request(
103
+ fill_query_params(kwargs.pop("path"), order_id),
104
+ params={**kwargs},
105
+ add_marketplace=False,
106
+ )
107
+
108
+ @sp_endpoint("/orders/v0/orders/{}/orderItems")
109
+ async def get_order_items(self, order_id: str, **kwargs) -> ApiResponse:
110
+ """
111
+ get_order_items(self, order_id: str, **kwargs) -> ApiResponse
112
+
113
+ Returns detailed order item information for the order indicated by the specified order ID.
114
+ If NextToken is provided, it's used to retrieve the next page of order items.
115
+
116
+ Note: When an order is in the Pending state (the order has been placed but payment has not been authorized),
117
+ the getOrderItems operation does not return information about pricing, taxes, shipping charges, gift status or
118
+ promotions for the order items in the order.
119
+ After an order leaves the Pending state (this occurs when payment has been authorized) and enters the Unshipped,
120
+ Partially Shipped, or Shipped state, the getOrderItems operation returns information about pricing, taxes,
121
+ shipping charges, gift status and promotions for the order items in the order.
122
+
123
+
124
+ **Usage Plan:**
125
+
126
+ ====================================== ==============
127
+ Rate (requests per second) Burst
128
+ ====================================== ==============
129
+ 1 1
130
+ ====================================== ==============
131
+
132
+
133
+
134
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
135
+
136
+ Examples:
137
+ literal blocks::
138
+
139
+ Orders().get_order_items('TEST_CASE_200')
140
+
141
+ Args:
142
+ order_id: str
143
+ key RestrictedResources: [str]
144
+ **kwargs:
145
+
146
+ Returns:
147
+ ApiResponse:
148
+
149
+ """
150
+ if "RestrictedResources" in kwargs:
151
+ kwargs.update(
152
+ {"original_path": fill_query_params(kwargs.get("path"), order_id)}
153
+ )
154
+ return self._access_restricted(kwargs)
155
+ return await self._request(
156
+ fill_query_params(kwargs.pop("path"), order_id), params={**kwargs}
157
+ )
158
+
159
+ @sp_endpoint("/orders/v0/orders/{}/address")
160
+ async def get_order_address(self, order_id, **kwargs) -> ApiResponse:
161
+ """
162
+ get_order_address(self, order_id, **kwargs) -> ApiResponse
163
+
164
+ Returns the shipping address for the order indicated by the specified order ID.
165
+
166
+ :note: To get useful information from this method, you need to have access to PII.
167
+
168
+ **Usage Plan:**
169
+
170
+ ====================================== ==============
171
+ Rate (requests per second) Burst
172
+ ====================================== ==============
173
+ 1 1
174
+ ====================================== ==============
175
+
176
+ Examples:
177
+ Orders().get_order_address('TEST_CASE_200')
178
+
179
+ Args:
180
+ order_id: str
181
+ **kwargs:
182
+
183
+ Returns:
184
+ ApiResponse
185
+ """
186
+ return await self._request(
187
+ fill_query_params(kwargs.pop("path"), order_id), params={**kwargs}
188
+ )
189
+
190
+ @sp_endpoint("/orders/v0/orders/{}/buyerInfo")
191
+ async def get_order_buyer_info(self, order_id: str, **kwargs) -> ApiResponse:
192
+ """
193
+ get_order_buyer_info(self, order_id: str, **kwargs) -> ApiResponse
194
+ Returns buyer information for the order indicated by the specified order ID.
195
+
196
+ :note: To get useful information from this method, you need to have access to PII.
197
+
198
+
199
+ **Usage Plan:**
200
+
201
+ ====================================== ==============
202
+ Rate (requests per second) Burst
203
+ ====================================== ==============
204
+ 1 1
205
+ ====================================== ==============
206
+
207
+
208
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
209
+
210
+ Examples:
211
+ Orders().get_order_buyer_info('TEST_CASE_200')
212
+
213
+ Args:
214
+ order_id: str
215
+ **kwargs:
216
+
217
+ Returns:
218
+ GetOrderBuyerInfoResponse:
219
+
220
+ """
221
+ return await self._request(
222
+ fill_query_params(kwargs.pop("path"), order_id), params={**kwargs}
223
+ )
224
+
225
+ @sp_endpoint("/orders/v0/orders/{}/orderItems/buyerInfo")
226
+ async def get_order_items_buyer_info(self, order_id: str, **kwargs) -> ApiResponse:
227
+ """
228
+ get_order_items_buyer_info(self, order_id: str, **kwargs) -> ApiResponse
229
+
230
+ Returns buyer information in the order items of the order indicated by the specified order ID.
231
+
232
+ **Usage Plan:**
233
+
234
+ ====================================== ==============
235
+ Rate (requests per second) Burst
236
+ ====================================== ==============
237
+ 1 1
238
+ ====================================== ==============
239
+
240
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
241
+
242
+ Examples:
243
+ literal blocks::
244
+
245
+ Orders().get_order_items_buyer_info('TEST_CASE_200')
246
+
247
+ Args:
248
+ order_id: str
249
+ key NextToken: str | retrieve data by next token
250
+
251
+ Returns:
252
+ ApiResponse
253
+ """
254
+ return await self._request(
255
+ fill_query_params(kwargs.pop("path"), order_id), params=kwargs
256
+ )
257
+
258
+ @sp_endpoint("/orders/v0/orders/{}/shipment", method="POST")
259
+ async def update_shipment_status(self, order_id: str, **kwargs) -> ApiResponse:
260
+ """
261
+ update_shipment_status(self, order_id: str, **kwargs) -> ApiResponse
262
+ Update the shipment status.
263
+ **Usage Plan:**
264
+ ====================================== ==============
265
+ Rate (requests per second) Burst
266
+ ====================================== ==============
267
+ 5 15
268
+ ====================================== ==============
269
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
270
+ Examples:
271
+ literal blocks::
272
+ Orders().update_shipment_status(
273
+ order_id='123-1234567-1234567',
274
+ marketplaceId='ATVPDKIKX0DER',
275
+ shipmentStatus='ReadyForPickup'
276
+ )
277
+ Args:
278
+ order_id: str
279
+ Returns:
280
+ ApiResponse
281
+ """
282
+ return await self._request(
283
+ fill_query_params(kwargs.pop("path"), order_id),
284
+ res_no_data=True,
285
+ data=kwargs,
286
+ )
287
+
288
+ @sp_endpoint("/orders/v0/orders/{}/shipmentConfirmation", method="POST")
289
+ async def confirm_shipment(self, order_id: str, **kwargs) -> ApiResponse:
290
+ """
291
+ confirm_shipment(self, order_id: str, **kwargs) -> ApiResponse
292
+ Updates the shipment confirmation status for a specified order.
293
+ **Usage Plan:**
294
+ ====================================== ==============
295
+ Rate (requests per second) Burst
296
+ ====================================== ==============
297
+ 2 10
298
+ ====================================== ==============
299
+ For more information, see "Usage Plans and Rate Limits" in the Selling Partner API documentation.
300
+ Examples:
301
+ literal blocks::
302
+ Orders().confirm_shipment(
303
+ order_id='123-1234567-1234567',
304
+ marketplaceId='ATVPDKIKX0DER',
305
+ packageDetail={
306
+ 'packageReferenceId': '0001',
307
+ 'carrierCode': 'DHL',
308
+ "shippingMethod": 'Paket',
309
+ 'trackingNumber': '1234567890',
310
+ 'shipDate': '2023-03-19T12:00:00Z',
311
+ 'orderItems': [
312
+ {
313
+ 'orderItemId': '123456789',
314
+ 'quantity': 1
315
+ },
316
+ {
317
+ 'orderItemId': '2345678901',
318
+ 'quantity': 2
319
+ },
320
+ ]
321
+ }
322
+ )
323
+ Args:
324
+ order_id: str
325
+ Returns:
326
+ ApiResponse
327
+ """
328
+ return await self._request(
329
+ fill_query_params(kwargs.pop("path"), order_id),
330
+ add_marketplace=False,
331
+ res_no_data=True,
332
+ data=kwargs,
333
+ )
334
+
335
+ @sp_endpoint("/tokens/2021-03-01/restrictedDataToken", method="POST")
336
+ async def _get_token(self, **kwargs):
337
+ data_elements = kwargs.pop("RestrictedResources")
338
+
339
+ restricted_resources = [
340
+ {
341
+ "method": "GET",
342
+ "path": kwargs.get("original_path"),
343
+ "dataElements": data_elements,
344
+ }
345
+ ]
346
+
347
+ return await self._request(
348
+ kwargs.pop("path"),
349
+ data={"restrictedResources": restricted_resources, **kwargs},
350
+ )
351
+
352
+ async def _access_restricted(self, kwargs):
353
+ if "original_path" not in kwargs:
354
+ kwargs.update({"original_path": kwargs["path"]})
355
+ token = self._get_token(**kwargs).payload
356
+ self.restricted_data_token = token["restrictedDataToken"]
357
+ r = await self._request(kwargs.pop("original_path"), params={**kwargs})
358
+ if not self.keep_restricted_data_token:
359
+ self.restricted_data_token = None
360
+ return r
361
+