Hello,
I have been working on a Python API to pull GONG user statistics into a fabric lakehouse. I have come across an issue where the cursor updates, but does not provide the second page of the report. Here is an example of the ‘records’ header
Call 1 (no cursor, first call):
{'totalRecords': 102, 'currentPageSize': 100, 'currentPageNumber': 0, 'cursor': 'eyJhbGciOiJIUzI1NiJ9.eyJwYWdlU2l6ZSI6MTAwLCJ0b3RhbCI6MTAyLCJwYWdlTnVtYmVyIjowLCJleHAiOjE3NDMxNzMxMjIsInVzZXJJZCI6ODg2NTQwMzAyNTgyNzEzNzU2NH0.lmaDwn5NH12Gnrou-hWF-H1PCiBaDL0XYrs6Qjc7ZS4'}
Call 2 (cursor included, second call, includes call url with cursor from call 1):
{'totalRecords': 102, 'currentPageSize': 100, 'currentPageNumber': 0, 'cursor': 'eyJhbGciOiJIUzI1NiJ9.eyJwYWdlU2l6ZSI6MTAwLCJ0b3RhbCI6MTAyLCJwYWdlTnVtYmVyIjowLCJleHAiOjE3NDMxNzMxMzEsInVzZXJJZCI6ODg2NTQwMzAyNTgyNzEzNzU2NH0.5prHg04LxA23xe-kQ76jU4cUs-pE4X9YucQ8KWHRU8E'}
Here is an example of my code:
#Block for testing the API pull params
startdate = "2025-02-01"
enddate = '2025-02-28'
filters = {
"filter":{
"fromDate": startdate,
"toDate": enddate,
#"createdFromDateTime": "1970-01-01T00:00:00.000Z",
#"createdToDateTime": "1970-01-01T00:00:00.000Z",
"userIds": list_userid
}
}
stats_url = "https://api.gong.io/v2/stats/activity/aggregate"
url = stats_url
headers = {
"Content-Type": "application/json"
}
#request data
response = requests.post(url,json=filters,auth=(access_key,secret_key),headers=headers)
#convert to json
response = response.json()
#normalize json
response_activitystats = pd.json_normalize(response['usersAggregateActivityStats'])
#show result
print(response['records'])
#Block for testing the cursor
all_dataframes = [] # Will hold each page's DataFrame
cursor = response['records']['cursor']
while True:
# Build the URL with or without a cursor
if cursor is not None:
url = f"{stats_url}?cursor={cursor}"
print(url)
break
else:
url = stats_url
print(url)
break
#Cursor Test 1
response = requests.post(url,json=filters,auth=(access_key,secret_key),headers=headers)
response = response.json()
cursor = response['records']['cursor']
url = f"{stats_url}?cursor={cursor}"
print(response['records'])
print(url)
The block testing the cursor goes though the header of each post and determines if it needs to loop the post again for more data. This works with the call for Users, but seems to have some issues with the post command and cursors.
I can’t seem to figure out why I am not getting the second page with just the two records. Does it have something to do with the list of users? I would have thought the cursor takes care of that.
Any thoughts are appreciated!
Thanks,
Dave