Skip to main content
Question

Gong API in Python - Aggregate Cursor not Progressing

  • March 28, 2025
  • 1 reply
  • 16 views

Forum|alt.badge.img

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):

https://api.gong.io/v2/stats/activity/aggregate?cursor=eyJhbGciOiJIUzI1NiJ9.eyJwYWdlU2l6ZSI6MTAwLCJ0b3RhbCI6MTAyLCJwYWdlTnVtYmVyIjowLCJleHAiOjE3NDMxNzMxMjIsInVzZXJJZCI6ODg2NTQwMzAyNTgyNzEzNzU2NH0.lmaDwn5NH12Gnrou-hWF-H1PCiBaDL0XYrs6Qjc7ZS4

{'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

1 reply

Molly Kipnis
Forum|alt.badge.img+2
  • Community Manager
  • 613 replies
  • April 8, 2025

Hey ​@Dave Toomey! Apologies for the delayed response here. 

As you're finding, some API calls that return a list are limited in the amount of records they may return, so multiple API calls may be required to bring all records.

API calls like this also returns a records field, which contains the number of records in the current page, the current page number and the total number of records.In cases where the total number of records exceeds the number of records thus far retrieved, the records field will also contain a cursor field which can be used to access the next page of records.

To retrieve the next page, repeat the API call with the cursor value as supplied by the previous API call. All other request inputs should remain the same.

For more specific help troubleshooting errors, please send your inquiry along with a full example of a call being passed and its return via this form and our Engineering Team will be happy to review.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings
×