H
H
hatorihanso2020-02-18 15:52:05
Python
hatorihanso, 2020-02-18 15:52:05

How to automate requests to the Python3 web interface (RestAPI)?

Good day, colleagues,

There is a need to upload a JSON file with data for a certain period of time from the web interface via RestAPI. The limit of entries in the received file is 100. The file itself contains information about the actions and the time when this action occurred. If there are more than 100 records for the requested period of time, the received response signals this - moreDataAvailable = True. To get the missing data, you need to form a new request and specify the time of the last received event (starttime) in the url and add 1 millisecond to it.

In Python, it was possible to make a request to the Web interface via requests.get ()

>>> import requests
>>> response = requests.get(
...     'https://api.blablabla.com/event/eventstatuses?requestId=1234&datetype=received&starttime=2020-02-10T00%3A00%3A57.001Z&...'
... )
>>> json_response = response.json()
>>> print(json_response)


How is it possible to automate queries to download all the necessary data for the requested period? (moreDataAvailable = False) Can the received JSONs be combined into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-02-18
@NeiroNx

Loop query based on data availability

DataAvailable = True
while DataAvailable:
   ... 
   DataAvailable = json_responce["MoreDataAvailable"] 
   start_time = new_start_time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question