|
29 | 29 | { |
30 | 30 | "cell_type": "code", |
31 | 31 | "id": "ef145f6d-ce8c-4c21-804e-254ca8190350", |
32 | | - "metadata": { |
33 | | - "ExecuteTime": { |
34 | | - "end_time": "2025-09-29T12:14:48.174450Z", |
35 | | - "start_time": "2025-09-29T12:14:46.832477Z" |
36 | | - } |
37 | | - }, |
| 32 | + "metadata": {}, |
38 | 33 | "source": [ |
39 | 34 | "pip install amzn-sp-api==1.2.0" |
40 | 35 | ], |
41 | | - "outputs": [ |
42 | | - { |
43 | | - "name": "stdout", |
44 | | - "output_type": "stream", |
45 | | - "text": [ |
46 | | - "Requirement already satisfied: amzn-sp-api==1.2.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (1.2.0)\r\n", |
47 | | - "Requirement already satisfied: urllib3<3.0.0,>=2.1.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from amzn-sp-api==1.2.0) (2.3.0)\r\n", |
48 | | - "Requirement already satisfied: certifi>=2025.1.31 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from amzn-sp-api==1.2.0) (2025.8.3)\r\n", |
49 | | - "Requirement already satisfied: requests>=2.32.3 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from amzn-sp-api==1.2.0) (2.32.3)\r\n", |
50 | | - "Requirement already satisfied: six>=1.17.0 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from amzn-sp-api==1.2.0) (1.17.0)\r\n", |
51 | | - "Requirement already satisfied: charset-normalizer<4,>=2 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from requests>=2.32.3->amzn-sp-api==1.2.0) (3.4.1)\r\n", |
52 | | - "Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from requests>=2.32.3->amzn-sp-api==1.2.0) (3.10)\r\n", |
53 | | - "\r\n", |
54 | | - "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.2.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.2\u001B[0m\r\n", |
55 | | - "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49m/usr/local/bin/python3 -m pip install --upgrade pip\u001B[0m\r\n", |
56 | | - "Note: you may need to restart the kernel to use updated packages.\n" |
57 | | - ] |
58 | | - } |
59 | | - ], |
60 | | - "execution_count": 1 |
| 36 | + "outputs": [], |
| 37 | + "execution_count": null |
61 | 38 | }, |
62 | 39 | { |
63 | 40 | "cell_type": "markdown", |
|
83 | 60 | { |
84 | 61 | "cell_type": "code", |
85 | 62 | "id": "4b7d9770-ccdc-4edd-a910-242916c578f7", |
86 | | - "metadata": { |
87 | | - "ExecuteTime": { |
88 | | - "end_time": "2025-09-29T12:15:13.908703Z", |
89 | | - "start_time": "2025-09-29T12:15:13.887970Z" |
90 | | - } |
91 | | - }, |
| 63 | + "metadata": {}, |
92 | 64 | "source": [ |
93 | 65 | "from spapi.models.datakiosk_v2023_11_15 import GetDocumentResponse, CreateQueryResponse, GetQueriesResponse, Query\n", |
94 | 66 | "from spapi import SPAPIConfig, SPAPIClient, ApiException, QueriesApi, ListingsApi\n", |
|
112 | 84 | "listings_api = ListingsApi(client.api_client)\n", |
113 | 85 | "print(\"💻 API Client initiated\")" |
114 | 86 | ], |
115 | | - "outputs": [ |
116 | | - { |
117 | | - "name": "stdout", |
118 | | - "output_type": "stream", |
119 | | - "text": [ |
120 | | - "💻 API Client initiated\n" |
121 | | - ] |
122 | | - } |
123 | | - ], |
124 | | - "execution_count": 5 |
| 87 | + "outputs": [], |
| 88 | + "execution_count": null |
125 | 89 | }, |
126 | 90 | { |
127 | 91 | "cell_type": "markdown", |
|
153 | 117 | "- Submit custom queries\n", |
154 | 118 | "- Check their status\n", |
155 | 119 | "- Download results\n", |
156 | | - " \n", |
| 120 | + "\n", |
157 | 121 | "🙌 Time to get seller data with the power of GraphQL!" |
158 | 122 | ] |
159 | 123 | }, |
160 | | - { |
161 | | - "metadata": {}, |
162 | | - "cell_type": "code", |
163 | | - "outputs": [], |
164 | | - "execution_count": null, |
165 | | - "source": "pip install pandas", |
166 | | - "id": "6cc8eb127ee0292b" |
167 | | - }, |
168 | 124 | { |
169 | 125 | "cell_type": "code", |
170 | 126 | "id": "7250c7cd-62cd-4ce3-9c40-db746184a37f", |
171 | | - "metadata": { |
172 | | - "ExecuteTime": { |
173 | | - "end_time": "2025-09-29T12:15:50.137187Z", |
174 | | - "start_time": "2025-09-29T12:15:49.991204Z" |
175 | | - } |
176 | | - }, |
| 127 | + "metadata": {}, |
177 | 128 | "source": [ |
178 | 129 | "graphql_query_str = (\"query { analytics_economics_2024_03_15 { economics( marketplaceIds: [\\\"ATVPDKIKX0DER\\\"], \"\n", |
179 | 130 | " \"startDate: \\\"2025-06-01\\\", endDate: \\\"2025-06-05\\\", \"\n", |
|
240 | 191 | "plt.tight_layout()\n", |
241 | 192 | "plt.show()\n" |
242 | 193 | ], |
243 | | - "outputs": [ |
244 | | - { |
245 | | - "name": "stdout", |
246 | | - "output_type": "stream", |
247 | | - "text": [ |
248 | | - "📃 Query: \n", |
249 | | - " query { analytics_economics_2024_03_15 { economics( marketplaceIds: [\"ATVPDKIKX0DER\"], startDate: \"2025-06-01\", endDate: \"2025-06-05\", aggregateBy: { date: DAY, productId: MSKU } ) { startDate endDate msku marketplaceId sales { unitsOrdered netUnitsSold netProductSales { amount currencyCode } } netProceeds { total { amount currencyCode } } } } }\n", |
250 | | - "✅ Query submitted! Response: {'query_id': '1000001'}\n", |
251 | | - "⏱️ Query status: {'created_time': datetime.datetime(2025, 7, 17, 11, 25, 13, 645000, tzinfo=tzutc()),\n", |
252 | | - " 'data_document_id': 'usecase_1_document_id.amzn.100001',\n", |
253 | | - " 'error_document_id': None,\n", |
254 | | - " 'pagination': None,\n", |
255 | | - " 'processing_end_time': datetime.datetime(2025, 7, 17, 11, 25, 13, 645000, tzinfo=tzutc()),\n", |
256 | | - " 'processing_start_time': datetime.datetime(2025, 7, 17, 11, 25, 13, 645000, tzinfo=tzutc()),\n", |
257 | | - " 'processing_status': 'DONE',\n", |
258 | | - " 'query': 'query { analytics_economics_2024_03_15 { economics( marketplaceIds: '\n", |
259 | | - " '[\"ATVPDKIKX0DER\"], startDate: \"2025-06-01\", endDate: \"2025-06-05\", '\n", |
260 | | - " 'aggregateBy: { date: DAY, productId: MSKU } ) { startDate endDate '\n", |
261 | | - " 'msku marketplaceId sales { unitsOrdered netUnitsSold '\n", |
262 | | - " 'netProductSales { amount currencyCode } } netProceeds { total { '\n", |
263 | | - " 'amount currencyCode } } } } }',\n", |
264 | | - " 'query_id': '1000001'}\n", |
265 | | - "📊 Here's your data: {'document_id': 'usecase_1_document_id.amzn.100001',\n", |
266 | | - " 'document_url': \"{'data': {'analytics_economics_2024_03_15': {'economics': \"\n", |
267 | | - " \"[{'startDate': '2025-06-01', 'endDate': '2025-06-01', \"\n", |
268 | | - " \"'msku': 'MOTOR-GEAR-US', 'marketplaceId': 'ATVPDKIKX0DER', \"\n", |
269 | | - " \"'sales': {'unitsOrdered': 0, 'netUnitsSold': 0, \"\n", |
270 | | - " \"'netProductSales': {'amount': 0.0, 'currencyCode': 'USD'}}, \"\n", |
271 | | - " \"'netProceeds': {'total': {'amount': 0.0, 'currencyCode': \"\n", |
272 | | - " \"'USD'}}}, {'startDate': '2025-06-01', 'endDate': \"\n", |
273 | | - " \"'2025-06-01', 'msku': 'MOTOR-GEAR-CA', 'marketplaceId': \"\n", |
274 | | - " \"'A2EUQ1WTGCTBG2', 'sales': {'unitsOrdered': 50, \"\n", |
275 | | - " \"'netUnitsSold': 50, 'netProductSales': {'amount': 1000.0, \"\n", |
276 | | - " \"'currencyCode': 'CAD'}}, 'netProceeds': {'total': {'amount': \"\n", |
277 | | - " \"800.0, 'currencyCode': 'CAD'}}}, {'startDate': '2025-06-01', \"\n", |
278 | | - " \"'endDate': '2025-06-01', 'msku': 'MOTOR-GEAR-MX', \"\n", |
279 | | - " \"'marketplaceId': 'A1AM78C64UM0Y8', 'sales': {'unitsOrdered': \"\n", |
280 | | - " \"50, 'netUnitsSold': 50, 'netProductSales': {'amount': \"\n", |
281 | | - " \"1000.0, 'currencyCode': 'Mex'}}, 'netProceeds': {'total': \"\n", |
282 | | - " \"{'amount': 800.0, 'currencyCode': 'Mex'}}}]}}}\"}\n" |
283 | | - ] |
284 | | - }, |
285 | | - { |
286 | | - "ename": "ModuleNotFoundError", |
287 | | - "evalue": "No module named 'pandas'", |
288 | | - "output_type": "error", |
289 | | - "traceback": [ |
290 | | - "\u001B[31m---------------------------------------------------------------------------\u001B[39m", |
291 | | - "\u001B[31mModuleNotFoundError\u001B[39m Traceback (most recent call last)", |
292 | | - "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[6]\u001B[39m\u001B[32m, line 22\u001B[39m\n\u001B[32m 19\u001B[39m \u001B[38;5;28mprint\u001B[39m(\u001B[33m\"\u001B[39m\u001B[33m📊 Here\u001B[39m\u001B[33m'\u001B[39m\u001B[33ms your data:\u001B[39m\u001B[33m\"\u001B[39m, get_document)\n\u001B[32m 21\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mast\u001B[39;00m\n\u001B[32m---> \u001B[39m\u001B[32m22\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpandas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpd\u001B[39;00m\n\u001B[32m 23\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mmatplotlib\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mpyplot\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mplt\u001B[39;00m\n\u001B[32m 25\u001B[39m \u001B[38;5;66;03m# Safely convert the string to a dictionary\u001B[39;00m\n", |
293 | | - "\u001B[31mModuleNotFoundError\u001B[39m: No module named 'pandas'" |
294 | | - ] |
295 | | - } |
296 | | - ], |
297 | | - "execution_count": 6 |
| 194 | + "outputs": [], |
| 195 | + "execution_count": null |
298 | 196 | }, |
299 | 197 | { |
300 | 198 | "cell_type": "markdown", |
|
327 | 225 | }, |
328 | 226 | { |
329 | 227 | "cell_type": "code", |
330 | | - "execution_count": null, |
331 | 228 | "id": "b1b36cbd-ca0a-4e4f-8e9f-edfc49fa053a", |
332 | 229 | "metadata": {}, |
333 | | - "outputs": [], |
334 | 230 | "source": [ |
335 | 231 | "import json\n", |
336 | 232 | "get_listing = listings_api.get_listings_item('AMY7FKRUBY7XV', \n", |
|
339 | 235 | " included_data=['issues'])\n", |
340 | 236 | "\n", |
341 | 237 | "print(\"🛍️ Here's your listing: \\n\", json.dumps(get_listing.to_dict(), indent=4, default=str))" |
342 | | - ] |
| 238 | + ], |
| 239 | + "outputs": [], |
| 240 | + "execution_count": null |
343 | 241 | }, |
344 | 242 | { |
345 | 243 | "cell_type": "markdown", |
|
454 | 352 | }, |
455 | 353 | { |
456 | 354 | "cell_type": "code", |
457 | | - "execution_count": null, |
458 | 355 | "id": "37f273da-1ba6-4698-b4f1-7d1db92d2a26", |
459 | 356 | "metadata": {}, |
460 | | - "outputs": [], |
461 | 357 | "source": [ |
462 | 358 | "import json\n", |
463 | 359 | "body = {\n", |
|
478 | 374 | "} \n", |
479 | 375 | "patch_listing = listings_api.patch_listings_item('AMY7FKRUBY7XV', 'MOTOR-GEAR-US',['ATVPDKIKX0DER'], body)\n", |
480 | 376 | "print(\"💾 Submission result: \\n\", json.dumps(patch_listing.to_dict(), indent=4, default=str))" |
481 | | - ] |
| 377 | + ], |
| 378 | + "outputs": [], |
| 379 | + "execution_count": null |
482 | 380 | }, |
483 | 381 | { |
484 | 382 | "metadata": {}, |
485 | 383 | "cell_type": "code", |
486 | | - "outputs": [], |
487 | | - "execution_count": null, |
488 | 384 | "source": "", |
489 | | - "id": "207ce43df479a203" |
| 385 | + "id": "207ce43df479a203", |
| 386 | + "outputs": [], |
| 387 | + "execution_count": null |
490 | 388 | } |
491 | 389 | ], |
492 | 390 | "metadata": { |
|
0 commit comments