我正在尝试使用市场卖家API来获取随身卡的订单。我正在使用https://seller.flipkart.com/api-docs/order-api-docs/SearchOrderRef.html网址。但是我只收到已取消的订单,而不是所有订单。请告诉我如何获取所有订单。这是我的职责谢谢。
def get_filter_orders(self):
api_address = f'{flipkart_api_url}/v2/orders/search'
filter_orders = Filter.objects.all()
for filter_order in filter_orders:
pass
payload = {"filter": {"states": ["APPROVED", "PACKED", "READY_TO_DISPATCH", "CANCELLED"],
"orderDate": {"fromDate": filter_order.order_date_from,
"toDate": filter_order.order_date_to},
"dispatchAfterDate": {"fromDate": filter_order.dispatch_after_date_from,
"toDate": filter_order.dispatch_after_date_to},
"dispatchByDate": {"fromDate": filter_order.dispatch_by_date_from,
"toDate": filter_order.dispatch_by_date_to},
"modifiedDate": {"fromDate": filter_order.modified_date_from,
"toDate": filter_order.modified_date_to}},
"pagination": {"pageSize": filter_order.page_size},
"sort": {"field": filter_order.sort_field, "order": filter_order.sort_order}}
headers = {
"Authorization": f"Bearer {access_token}",
"content-type": "application/json",
}
response = requests.post(api_address, data=json.dumps(payload, cls=DjangoJSONEncoder), headers=headers)
dict_response = response.json()
orderData = dict_response.get('orderItems', '')
for orderItem in orderData:
orders_data = {}
if orderItem.get('orderId'):
orders_data['order_id'] = orderItem.get('orderId')
orders_data['order_item'] = orderItem.get('orderItemId')
orders_data['title'] = orderItem.get('title')
orders_data['sku'] = orderItem.get('sku')
orders_data['order_date'] = orderItem.get('orderDate')
only_date = orders_data['order_date'].split('T')[0]
# print(only_date)
orders_data['deliver_by_date'] = orderItem.get('deliverByDate')
orders_data['status'] = orderItem.get('status', '')
orders_data['total_price'] = orderItem['priceComponents']['totalPrice']
# print(orders_data['total_price'])
# import pdb;pdb.set_trace()
try:
Orders.objects.update_or_create(order_id=orders_data['order_id'],
order_item=orders_data['order_item'], title=orders_data['title'],
sku=orders_data['sku'], order_date=only_date,
deliver_by_date=orders_data['deliver_by_date'],
status=orders_data['status'],
total_price=orders_data['total_price'])
print('created', Orders.objects.count())
except Exception as e:
print("Order ID already exists", e)
return dict_response