# Python - how do I loop through API response to get properties values

**URL:** <https://community.hubspot.com/t/python-how-do-i-loop-through-api-response-to-get-properties-values/105749>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [April 25, 2024, 9:23am UTC](https://community.hubspot.com/t/python-how-do-i-loop-through-api-response-to-get-properties-values/105749 "2024-04-25T09:23:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSingh42](https://avatars.discourse-cdn.com/v4/letter/k/6f9a4e/32.png) [@KSingh42](https://community.hubspot.com/u/KSingh42)\
**Post date:** [April 25, 2024, 9:23am UTC](https://community.hubspot.com/t/python-how-do-i-loop-through-api-response-to-get-properties-values/105749/1 "2024-04-25T09:23:32Z")

</div>

Hey - im using python but im unable to loop through my API response. Im using the search api and the api response looks something like this. What I need are the values of the properties. Basically I need the firstname and hs\_object\_id of each user. I have also tried this out on my own but the last line (print(i)) only gives me the words of the properties

```lia-code-sample
api_response = client.crm.contacts.search_api.do_search(public_object_search_request=public_object_search_request)
 for data in api_response._results:
 for i in data._properties:
 print(i)​

```

```lia-code-sample
{'paging': None,
 'results': [{'archived': False,
 'archived_at': None,
 'created_at': datetime.datetime(2024, 3, 27, 9, 13, 6, 633000, tzinfo=tzutc()),
 'id': '1111',
 'properties': {'createdate': '2024-03-27T09:13:06.633Z',
 'firstname': 'Name1',
 'hs_object_id': '1111'},
 'properties_with_history': None,
 'updated_at': datetime.datetime(2024, 4, 25, 5, 33, 40, 551000, tzinfo=tzutc())},
 {'archived': False,
 'archived_at': None,
 'created_at': datetime.datetime(2024, 2, 26, 7, 31, 57, 197000, tzinfo=tzutc()),
 'id': '1112',
 'properties': {'createdate': '2024-02-26T07:31:57.197Z',
 'firstname': 'Name2',
 'hs_object_id': '1112',
 },
 'properties_with_history': None,
 'updated_at': datetime.datetime(2024, 4, 25, 7, 19, 58, 332000, tzinfo=tzutc())},

```

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [April 25, 2024, 4:24pm UTC](https://community.hubspot.com/t/python-how-do-i-loop-through-api-response-to-get-properties-values/105749/2 "2024-04-25T16:24:51Z")

</div>

Hi, @KSingh42 👋 I know enough to be dangerous, but I am not an expert by any means. Have you tried using the get method?

Something like

```lia-code-sample
api_response = client.crm.contacts.search_api.do_search(public_object_search_request=public_object_search_request)
for data in api_response._results:
 properties = data.get('properties', {})
 firstname = properties.get('firstname')
 hs_object_id = properties.get('hs_object_id')
 print(f'Firstname: {firstname}, HS Object ID: {hs_object_id}')

```

Best,

Jaycee
