Hello all,
In API Documentation, I see that there are two ‘variebles’ in the response:
- hasMore
- Offset
In the deault code provided by the documentation, I removed the ‘max_results’ condition.
import requests
import json
import urllib
#max_results = 500
hapikey = 'demo'
limit = 250
deal_list = []
get_all_deals_url = "https://api.hubapi.com/deals/v1/deal/paged?"
parameter_dict = {'hapikey': hapikey, 'limit': limit}
headers = {}
# Paginate your request using offset
has_more = True
while has_more:
parameters = urllib.parse.urlencode(parameter_dict)
get_url = get_all_deals_url + parameters
r = requests.get(url= get_url, headers = headers)
response_dict = json.loads(r.text)
has_more = response_dict['hasMore']
deal_list.extend(response_dict['deals'])
parameter_dict['Offset']= response_dict['offset']
print(response_dict['offset'])
print(response_dict['hasMore'])
print('loop finished')
list_length = len(deal_list)
print("You've succesfully parsed through {} deal records and added them to a list".format(list_length))
So, I expect the script to finish when ‘has_more’ attribute is False. But this will never happen, neither in the demo, nor in our company deals.
The API answers ‘True’ and the same ‘Offset’ for all iterations.
Is this the default behaviour?