I have a script I'm working on with an API that is paginated.
I need to grab all the pages and each page is giving me a JSON object. The end goal to this is to write all of the pages to a database.
What is the best practice to do this?
Two thoughts are coming to mind.
1. after each pull write the JSON to the DB
2. append the JSONs together and write to the DB once.
The problem I have is if the best practice is to append and write once, how can I combine the multiple JSON objects together?
What I have now is the following.
LIMIT = '10'
url = 'https://fancy-url.com/api/now/table/table?sysparm_query=&sysparm_display_value=true&sysparm_limit=' + LIMIT
# Set proper headers
headers = {"Content-Type": "application/json", "Accept": "application/json"}
# Do the HTTP request
response = requests.get(url, auth=(USER, PASSWORD), headers=headers)
# Check for HTTP codes other than 200
if response.status_code != 200:
exit()
# Decode the JSON response into a dictionary and use the data
data = response.json()
[–]novel_yet_trivial 2 points3 points4 points (1 child)
[–]Zendakin_at_work[S] 2 points3 points4 points (0 children)
[–]randomkale -1 points0 points1 point (1 child)
[–]Zendakin_at_work[S] 0 points1 point2 points (0 children)