Hi All,
I am just starting out with HubSpot and am after some help with gathering data using Python.
I am currently using the below code to gather custom objects which I will eventually expand.
The below code works for gathering information when there only enough contacts for 1 page, though wont gather information if the number of contacts exceeds this?
Spoiler
import pandas as pd
from hubspot import HubSpot
from hubspot.crm.contacts.exceptions import ApiException
from pandasgui import show
def extract_all_contacts():
api_client = HubSpot(access_token=‘insert-token-here’)
custom_property_names = [‘firstname’, ‘lastname’]
df = pd.DataFrame()
params = {“limit”: 100, “archived”: False}
all_contacts = []
while True:
try:
contacts_page = api_client.crm.contacts.get_all(**params)
all_contacts.extend(contacts_page)
except ApiException as e:
print(“Exception when requesting Contacts by id: %s\n” % e)
break
if not contacts_page:
break
for contact in contacts_page:
contact_properties = {
name: contact.properties.get(name, None) for name in custom_property_names
}
df_properties = pd.DataFrame([contact_properties])
df = pd.concat([df, df_properties], ignore_index=True)
if len(contacts_page) < params[“limit”]:
break
params[“after”] = contacts_page[-1].id
show(df)
extract_all_contacts()
so with the above code I am getting the following error:
TypeError: hubspot.crm.contacts.api.basic_api.BasicApi.get_page() got multiple values for keyword argument ‘after’
anyone any ideas?