saleweaver/python-amazon-sp-api

interval date error in Sales.get_order_metrics()

chimp-rb opened this issue · 3 comments

Describe the bug
While passing a tuple of datetime to interval param, raises error

sp_api.base.exceptions.SellingApiBadRequestException: [{'code': 'InvalidInput', 'message': '{getOrderMetrics.arg1=must match "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{3})?(([+-]\\d\\d:\\d\\d)|Z)(\\[[a-zA-Z/_]+\\])?--[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{3})?(([+-]\\d\\d:\\d\\d)|Z)(\\[[a-zA-Z/_]+\\])?"}', 'details': ''}]

To Reproduce

today = datetime.now()
last_month = today-timedelta(days=30)
x = Sales().get_order_metrics(interval=(last_month, today), granularity=Granularity.DAY)

Expected behavior

_create_datetime_stamp function should parse the datetime into proper format.
Suggested solution : return datetime_obj.astimezone().isoformat(timespec="seconds") , this is compatible with python3.6+

Desktop (please complete the following information):

  • OS: Windows

@chimp-rb Thanks I was tearing my hair out with this and just assumed I was doing something wrong.
@saleweaver I can confirm the fix proposed works I am still too armature to know how to create a PR and make this simple fix in the repo.

@saleweaver
If you approve, I am available to take-up this issue.

Hi guys! If you can create a PR that'll be great, I can do it the next few days too. 😄