import requests
import time
ozon_packaging = requests.post("https://api-seller.ozon.ru/v3/posting/fbs/unfulfilled/list", headers = {'Client-Id':'XXXXXX','Api-Key': 'XXXXXXXXXXXXX',},json = {'dir': 'asc','filter': {'status': 'awaiting_packaging','cutoff_from': '2023-01-01T14:15:22Z','cutoff_to': '2024-01-01T14:15:22Z'},'limit': '100','offset': '0',})
for i in range(len(ozon_packaging.json()['result']['postings'])):
zakaz = ozon_packaging.json()['result']['postings'][i]
print(zakaz)
tovar = []
for a in range(len(zakaz["products"])): tovar.append({"product_id": zakaz["products"][a]["sku"], "quantity": zakaz["products"][a]["quantity"]})
print(tovar) # Товар и количество купленный в заказе
print(type(tovar))
# Сборка заказа
ozon_packaging = requests.post("https://api-seller.ozon.ru/v4/posting/fbs/ship",
headers={'Client-Id': 'XXXXXXXX', 'Api-Key': 'XXXXXXXXXXXXXXXXXX'},
json={'posting_number': zakaz["posting_number"],
'packages': [{"products": tovar}],
'with': {"additional_data": True}})
print("собрал")
{'posting_number': '27676762-0078-1', 'order_id': 8020760202, 'order_number': '27676762-0078', 'status': 'awaiting_packaging', 'delivery_method': {'id': 1020000119855000, 'name': 'Доставка Ozon самостоятельно, Ейск', 'warehouse_id': 1020000119855000, 'warehouse': 'Склад на шевченко', 'tpl_provider_id': 24, 'tpl_provider': 'Доставка Ozon'}, 'tracking_number': '', 'tpl_integration_type': 'ozon', 'in_process_at': '2023-03-10T09:31:15Z', 'shipment_date': '2023-03-12T10:00:00Z', 'delivering_date': None, 'cancellation': {'cancel_reason_id': 0, 'cancel_reason': '', 'cancellation_type': '', 'cancelled_after_ship': False, 'affect_cancellation_rating': False, 'cancellation_initiator': ''}, 'customer': None, 'products': [{'price': '370.000000', 'offer_id': '654545', 'name': 'STLINK-V2 отладчик и программатор STM32', 'sku': 848241348, 'quantity': 1, 'mandatory_mark': [], 'currency_code': 'RUB'}], 'addressee': None, 'barcodes': None, 'analytics_data': None, 'financial_data': None, 'is_express': False, 'requirements': {'products_requiring_gtd': [], 'products_requiring_country': [], 'products_requiring_mandatory_mark': [], 'products_requiring_rnpt': []}, 'parent_posting_number': '', 'available_actions': ['cancel', 'ship'], 'multi_box_qty': 1, 'is_multibox': False, 'substatus': 'posting_created'}
[{'product_id': 848241348, 'quantity': 1}]
<class 'list'>
собрал
Traceback (most recent call last):
File "C:\Users\Kryshenko_IV\PycharmProjects\OZON\main.py", line 12, in <module>
zakaz = ozon_packaging.json()['result']['postings'][i]
TypeError: list indices must be integers or slices, not str