# Python - Getting Custom Contacts Information

**URL:** <https://community.hubspot.com/t/python-getting-custom-contacts-information/95013>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [November 29, 2023, 10:34am UTC](https://community.hubspot.com/t/python-getting-custom-contacts-information/95013 "2023-11-29T10:34:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Common](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@Common](https://community.hubspot.com/u/Common)\
**Post date:** [November 29, 2023, 10:34am UTC](https://community.hubspot.com/t/python-getting-custom-contacts-information/95013/1 "2023-11-29T10:34:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![LewTalon](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@LewTalon](https://community.hubspot.com/u/LewTalon)\
**Post date:** [November 30, 2023, 2:54am UTC](https://community.hubspot.com/t/python-getting-custom-contacts-information/95013/2 "2023-11-30T02:54:33Z")

</div>

Hi @Common

Taking a peak at the Python library here: [hubspot-api-python/README.md at master · HubSpot/hubspot-api-python · GitHub](https://github.com/HubSpot/hubspot-api-python/blob/master/README.md)

It does mention that

`api_client.crm.contacts.get_all`

already includes pagination. It states: “Please note that pagination is used under the hood to get all results.” So this may be why you’re receiving just the first page?

I would recommend trying this instead:

`client.crm.contacts.default_api.get_page(limit=100, archived=False)`

Then you can read through each page.

I’ve noticed sometimes the client doesn’t work with every single request, so sometimes just referring to the API docs and using the direct endpoint is better.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![SMukherjee9](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/smukherjee9/32/200746_2.png) [@SMukherjee9](https://community.hubspot.com/u/SMukherjee9)\
**Post date:** [November 30, 2023, 4:07am UTC](https://community.hubspot.com/t/python-getting-custom-contacts-information/95013/3 "2023-11-30T04:07:31Z")

</div>

Thank You!
