I am writing a script to automate the extraction of a report via API, I came across a problem where the API limits the query to one page (x-page) at a time. How could I change this page to this last amount? And how to insert the new information after the page change in the file I'm generating?
Could you please help me?
url="https://api.example.com.br/company/7/history?createdFrom:2019:11:21T07:00:000updatedTo:2019:11:21T08:00:000Z"
heards = {
"x-page": "1",
"Content-Type": "application/json",
"Authorization": bearer_token
}
r = requests.get(url, headers=heards)
file = open('data-history.json', 'wb')
for x in r:
file.write(x)
file.close()
data = tablib.Dataset(headers=(
'id', 'name', 'messages_count', 'last_message_at', 'status_id', 'created_at', 'updated_at', 'company_id',
'contact_id', 'sector_id', 'channelable_id', 'channelable_type', 'is_json', 'last_user_id', 'closed_at',
'first_message_at', 'protocol', 'first_start_chat_at', 'first_operator_answer_at', 'latest_contact_chat_message_at',
'latest_operator_answer_at', 'waiting_time_medium', 'waiting_time_count', 'last_message_by_operator', 'closed_by_user_id',
'operator_assigned_id', 'sla_count', 'is_auto')
)
import_filename = 'data-history.json'
data.json = open(import_filename, 'r').read()
data_export = data.export('xlsx')
with open('/home/mgsoares/Documentos/API/file.xlsx', 'wb') as f:
f.write(data_export)
f.close()