JimCurryWang / python-shopee

pyshopee - Shopee Partner API Client for Python
https://pypi.org/project/pyshopee
MIT License
215 stars 82 forks source link

order list retrieve only one year worth of order #12

Closed essramos closed 5 years ago

essramos commented 5 years ago

Is this possible on the https://partner.shopeemobile.com/api/v1/orders/get endpoint?

JimCurryWang commented 5 years ago

@essramos What did you mean?

If you want to fetch special time range of orders, you can try to set the create_time_from and create_time_to params.

Here is the official document : https://open.shopee.com/documents?module=4&type=1&id=398

essramos commented 5 years ago

Actually the time range maximum is only 15 days. Sorry I guess I Should be asking shopee support. I just can't find where to ask it.

JimCurryWang commented 5 years ago

Yeah, the time range maximum is only 15 days, however, you can use a for loop to make requests on it each batch for 15 days.

If you have any further question or advice, please don't hesitate to contact me.

essramos commented 5 years ago

This is really smart. thanks a lot, I was trying this on their sandbox, but the filters don't really work there.

Thanks for this library as well. Really helpful!

essramos commented 5 years ago

Oh for anyone reading this, the filters created_time_from and created_time_to are not working, this isn't the libraries fault because I also tried raw http request, I think it is shopee. I tried 15 days ranges, and it still returning me everything. This is on get_order_by_status()

JimCurryWang commented 5 years ago

Hi, @essramos
Maybe your shop is newborn, so you can only filter all order even you use the time range condition.

Note that the create_time_from and create_time_to fields specify a date range for retrieving orders (based on the order create time). However, the return params will be update_time which indicates the last time that there was a change in value of order, such as order status changed from 'PAID' to 'COMPLETED'.

import pyshopee
shopee = pyshopee.Client(shop_id = 37130000, partner_id = 800000, secret_key = 'xxxxxxxxxxxxxxxxxxx052xxxxxxxxxxxxxxxxx')
resp = shopee.order.get_order_by_status(order_status="COMPLETED",create_time_from = 1512117303, create_time_to=1512635703)
print(resp)
{
'request_id': 'gxxxVsxxxxxxxxxxzXSnF',
'orders': [
    {'ordersn': '17120xxxxxxxxx7', 'update_time': 1515723444, 'order_status': 'COMPLETED'}, 
    {'ordersn': '17120xxxxxxxxxH', 'update_time': 1515549595, 'order_status': 'COMPLETED'} 
]
, 'more': True}
essramos commented 5 years ago

@JimCurryWang I was using created_time_from instead of create_time_from. I got it to filter. Another thing I notice is it's excluding records on dates that are the same with the create_time_from or create_time_to. Have you noticed that? Driving myself crazy here.

say my create_time_from date is '2019-03-01' in epoch, and a record has a create time '2019-03-01' as well, this is excluded from the result.

JimCurryWang commented 5 years ago

@essramos I just make a test on this issue and I am sure that the time setting is count to "second".

That is to say, if you have an order created on 2019-03-01 23:57:36 +0800 then you should set your created_time_from to 1551455856(2019-03-01 23:57:36 ) instead of 1551455820(2019-03-01 23:57:00).

# an order which timestamp  is 1551455856 (2019-03-01 23:57:36 GMT+08:00)
resp = shopee.order.get_order_list(create_time_from =1551455856, create_time_to=1551455856)
essramos commented 5 years ago

You are right, it is counting to seconds, I had to make sure my epoch time starts at 00:00:00 Hr and ends at 23:59:59. Thank you very much for your help!