HubSpot / hubspot-api-python

HubSpot API Python Client Libraries for V3 version of the API
Apache License 2.0
336 stars 107 forks source link

How to retrieve "all" items (for their ids) without properties #357

Closed CribberSix closed 4 days ago

CribberSix commented 3 weeks ago

I am trying to retrieve all items without any properties - my goal is to get all existing ids into a list.

I figured that it would be faster if I can tell HubSpot not to return any properties, but just the "base" object which already contains the id.

But I cannot figure out how to get it to work - no matter what I pass to the "properties" parameter, I always get some properties back. Any ideas?

# various attempts
contacts = api_client.crm.contacts.get_all(properties=None) 
contacts = api_client.crm.contacts.get_all(properties=[]) 
contacts = api_client.crm.contacts.get_all(properties=["none"]) 

# return 
{'archived': False,
 'archived_at': None,
 'associations': None,
 'created_at': datetime.datetime(2022, 2, 1000, 0, 0, 340000, tzinfo=tzutc()),
 'id': '1',
 'properties': {'createdate': '2022-02-10T10:00:00:0000',
                'hs_object_id': '1',
                'lastmodifieddate': '2022-02-17T00:00:00.372Z'},
 'properties_with_history': None,
 'updated_at': datetime.datetime(2022, 9, 17, 0, 8, 5, 372000, tzinfo=tzutc())}
alzheltkovskiy-hubspot commented 4 days ago

Hey @CribberSix.The createdate, hs_object_id, and lastmodifieddate properties are basic system fields that cannot be excluded from the response because they are built into the contacts structure. If you want to get only contact ids you can try something like this:

contacts = api_client.crm.contacts.get_all()
only_ids = [contact.id for contact in api_response]
CribberSix commented 4 days ago

Ahh alright, thanks for the clarification!