# Not able to get the custom property value from Ticket API response in Python

**URL:** <https://community.hubspot.com/t/not-able-to-get-the-custom-property-value-from-ticket-api-response-in-python/89125>\
**Category:** APIs & Integrations\
**Tags:** starter\
**Created:** [September 7, 2023, 2:58am UTC](https://community.hubspot.com/t/not-able-to-get-the-custom-property-value-from-ticket-api-response-in-python/89125 "2023-09-07T02:58:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BBTBCD](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@BBTBCD](https://community.hubspot.com/u/BBTBCD)\
**Post date:** [September 7, 2023, 2:58am UTC](https://community.hubspot.com/t/not-able-to-get-the-custom-property-value-from-ticket-api-response-in-python/89125/1 "2023-09-07T02:58:58Z")

</div>

I’m try to get the value of the custom property that i’ve added in the Ticket properties. I can able to get the json response from the Ticket APi and display all of the ticket number(objectId) but when i try to display the value of the custom property that i created i’m getting “KeyError: ‘ref\_num’”  
Json response:  
{‘portalId’: 43680158, ‘objectType’: ‘TICKET’, ‘objectId’: 1888262026, ‘properties’: {‘ref\_num’: {‘versions’: [{‘name’: ‘ref\_num’, ‘value’: ‘423011’, ‘timestamp’: 1694045255743, ‘sourceId’: ‘2069329’, ‘source’: ‘INTEGRATION’, ‘sourceVid’: [], ‘requestId’: ‘6514e376-91b6-4080-9786-2245a30d04bb’, ‘useTimestampAsPersistenceTimestamp’: True}], ‘value’: ‘423011’, ‘timestamp’: 1694045255743, ‘persistenceTimestamp’: 1694045255743, ‘source’: ‘INTEGRATION’, ‘sourceId’: ‘2069329’, ‘updatedByUserId’: None}}, ‘isDeleted’: False}

{‘portalId’: 43680158, ‘objectType’: ‘TICKET’, ‘objectId’: 1888290979, ‘properties’: {‘ref\_num’: {‘versions’: [{‘name’: ‘ref\_num’, ‘value’: ‘423009’, ‘timestamp’: 1694045254773, ‘sourceId’: ‘2069329’, ‘source’: ‘INTEGRATION’, ‘sourceVid’: [], ‘requestId’: ‘5d051f4d-3eb8-4950-b08f-6db274dec6d0’, ‘useTimestampAsPersistenceTimestamp’: True}], ‘value’: ‘423009’, ‘timestamp’: 1694045254773, ‘persistenceTimestamp’: 1694045254773, ‘source’: ‘INTEGRATION’, ‘sourceId’: ‘2069329’, ‘updatedByUserId’: None}}, ‘isDeleted’: False}

My code (Display ticket number (working)

`url = "https://api.hubapi.com/crm-objects/v1/objects/tickets/paged?properties=ref_num"response = request("get", url)jsonTickets = response.json()for ticket in jsonTickets['objects']: print(format(ticket['objectId'])) **********Displays:18882620261888290979********* `

My code (Display ref\_num (not - working)

`url = "https://api.hubapi.com/crm-objects/v1/objects/tickets/paged?properties=ref_num"response = request("get", url)jsonTickets = response.json()for ticket in jsonTickets['objects']: print(format(ticket['ref_num']))******Error: print(format(ticket['ref_num'])) ~~~~~~ ^^^^^^^^^^^^^^^KeyError: 'ref_num'**********`

How do i get the value of “ref\_num” to display. My apologies if i’m new to python. Appreciate the help. Thanks

---

<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:** [September 7, 2023, 5:51pm UTC](https://community.hubspot.com/t/not-able-to-get-the-custom-property-value-from-ticket-api-response-in-python/89125/2 "2023-09-07T17:51:46Z")

</div>

Hi, @BBTBCD 👋 Thanks for the great question! I am not a regular Python user, and I’m happy to help.

Thought one — I wonder if this error happening because the property is nested one level deeper in `properties`. Maybe try adjusting your code like this? ([Stack Overflow post I referenced](https://stackoverflow.com/questions/48550533/accessing-nested-objects-with-python))

```lia-code-sample
for ticket in jsonTickets['objects']:
 print(format(ticket['properties']['ref_num']['value']))

```

Additionally, have you looked into implanting the [Python Dictionary get() Method](https://www.w3schools.com/python/ref_dictionary_get.asp)? This would allow you to account for when there is no value present for a requested object. It will return either the value for the property or a default value, like `None`, for cases where the property is blank or null. And help prevent potential `KeyError`s in the future.

Have fun building! — Jaycee

---

<div class="post-metadata">

**Author:** ![BBTBCD](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@BBTBCD](https://community.hubspot.com/u/BBTBCD)\
**Post date:** [September 7, 2023, 6:46pm UTC](https://community.hubspot.com/t/not-able-to-get-the-custom-property-value-from-ticket-api-response-in-python/89125/3 "2023-09-07T18:46:56Z")

</div>

Hey Jaycee

I just tried it and it’s PERFECT !!! Really appreciate the help.  
Thanks
