0

Below is the code i am using to get values from the repositories. Here i have given like to give data from only page 1. But how to get data from all the pages existing in that repository using loop. And again these data will be posted back to another URL using Post method.

import requests
import json

headers = {
    'Content-Type': 'application/json, Accept: application/json',
 }

params = (
    ('dql', 'select u.user_name as USER_NAME,u.user_login_name as USER_LOGIN,u.default_folder as 
DEFAULT_FOLDER_PATH, u.last_login_utc_time as USER_LAST_LOGIN, u.user_os_domain as 
USER_OS_DOMAIN,u.user_login_domain as USER_LOGIN_DOMAIN,u.user_state as USER_STATE,f.object_name as 
DEFAULT_FOLDER_NAME,f.r_creation_date as DEFAULT_FOLDER_CREATION_DATE,f.r_modify_date as 
DEFAULT_FOLDER_MODIFY_DATE from dm_user u, dm_folder f where u.default_folder = f.r_folder_path 
enable(ROW_BASED)'),
    ('items-per-page', '2'),
    ('page', '1'),
)
def requestcall():
  myResponse = requests.get('https://1.1.1.1/rest/repositories/hhdht@@', headers=headers, 
params=params, verify=False, auth=('@@@@@@', '#######'))
  print(myResponse.status_code)
    # For successful API call, response code will be 200 (OK)
  if myResponse.ok:

        # extracting data in json format
   data = myResponse.json()


  return data
requestcall()

1 Answer 1

2

Well, you can put page variable inside the for loop until it reach the max_page number like this?

def requestcall():
  for p in range(max_page):
     params=(
      ('dsql','...')
      ('page',str(p))
      ('item-per-page','2')
     )
     request.get(...params=params)
Sign up to request clarification or add additional context in comments.

4 Comments

Here i dont know the last page number for the repository to give in the range. And for each repository the number of pages may change. Do you have any idea..How can i get the data until the last page of repository
@saffron an api usually has the way to return total page or total record from one query (then you can use it to calculate total page)
Don't we have anyother options like using Pointer or something
@saffron you could check the request status, if it got error status, or null returned data after few page, then the last one is the max page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.