Cursor value is not null

Hello, I need help with my Python code where I am retrieving element information from all boards specified in a table named: df_boards_norm. But i run into a problem that in some boards there are more then 500 items (and i have a limit of 500, I cant change this part), and the cursor then is not null. I need somehow to check if the cursor is not null to run the code again with the same board id where it left of, but if it comes on null, run other boards like normal.
Thie is my part of the code:

pulse_1 = pd.DataFrame()
for i in range(len(df_boards_norm)):
    q_pulses = (
        "{boards(ids:"
        + df_boards_norm.loc[i, "id"]
        + "){items_page (limit:500){cursor items{id name column_values (types: time_tracking){value}}}}}" 
    )
    data_pulses = {"query": q_pulses}
    r_pulses = requests.post(url=apiUrl, json=data_pulses, headers=headers)

    pulses_json = r_pulses.json()
    df_pulses_norm = pd.json_normalize(
        pulses_json['data']['boards'][0]['items_page'],
        record_path=['items', 'column_values'],
        meta=[
            ['items', 'id'],
            ['items', 'name'],
        ],
        errors="ignore",
    )
    df_pulses_norm.insert(0, "board_id", df_boards_norm.loc[i, "id"])
    pulse_1 = pd.concat([pulse_1, df_pulses_norm], ignore_index=True)
    
pulse_1['value'] = pulse_1['value'].apply(lambda x: {} if pd.isna(x) else x)    
pulse_1 = pulse_1[pulse_1['value'] != {}].reset_index()
pulse_1.head()

Also, is there a possibility to add more: so it will take more columns from monday. Something like this:

{cursor items{id updated_at name column_values (types: time_tracking){value … on TimeTrackingValue
{
running
started_at
updated_at
history
{
started_at
ended_at
started_user_id
ended_user_id
}
}
}}}}}

I just do not know how to incorporate these two things into my code. I will be really pleased if someone will help me, because in this part right now I feel helpless :frowning:

Try making the first API call, then using a while loop – that will repeat as long as the cursor is NOT null.

How can I do that?

My Python is rusty so I will not write you an example, but here are the general steps:

  1. Make your first API call – get the first batch of items from the board, and a cursor
  2. Assign a variable currentCursor to the cursor
  3. Start a while loop, something like:
while currentCursor is not None:
   [cursor, items] = getNextItemPage() 
   currentCursor = cursor # set the cursor from the API call to "currentCursor"
  1. After the while loop, continue the rest of your app’s logic.

The while loop is a special kind of loop that will continue as long as the condition is true - in this case, as long as your API call returns a cursor and there are more items to get, it will keep running.