Home > Mobile >  date range filter API with python
date range filter API with python

Time:06-18

I'm a beginner in python, and I want to get data from API, below is the documentation enter image description here

and this is the code that I write

import requests
import json
from requests.auth import HTTPBasicAuth

r = requests.get('https://blabla.com/get-sales-information', auth=HTTPBasicAuth('username', 'pass'))

I got the status_code=404 because it need date filter. But I don't have any clue to put date filter, its so stupid but I really don't know how to. Already trying to search in many different platform but still not solved

this is the sample data that I want to print

[
    {
        "salesNum": "12333",
        "billNum": "2132123",
        "salesDate": "2021-03-16",
        "salesDateIn": "2021-03-16 15:17:16",
        "salesDateOut": "2021-03-17 09:36:33",
        "branchCode": "DBX",
        "branchName": "Bracnh",
        "memberCode": null,
        "memberName": null,
     }
]

CodePudding user response:

Are you asking on how the date format should be? or how to actually include body on a requests module?

  1. As for date format, It's unclear unless example was specified, However considering your response is looks like it would be "2022-06-16" format.

  2. Since content-type = application/json, this :

request_body = {
 "filterSalesDateFrom" : "2022-03-16",
 "filterSalesDateTo" : "2022-03-17"
}

r = requests.get('https://blabla.com/get-sales-information', 
json = request_body,
auth=HTTPBasicAuth('username', 'pass')
)
  • Related