APIs & Integrations

klloyd__1
Participant | Gold Partner
Participant | Gold Partner

Reading "hubspotDefined": true in Python

SOLVE

Hello friends,

 

I'm working on a Python script that will read object properties, and needs to determine whether or not a property is one of the default properties created by HubSpot.  I'm running into issues in Python determining whether the "hubspotDefined" value is True.  JSON returns as "true", whereas Python looks for "True".  I've read some articles on other sites but was hoping that someone has already done this particular excersise on the values returned by HubSpot's properties API. 

 

Example of one of the properties returned in read all properties API:

 {
            "updatedAt": "2019-09-23T17:45:44.354Z",
            "createdAt": "2019-08-06T02:41:10.544Z",
            "name": "hs_searchable_calculated_international_mobile_number",
            "label": "Calculated Mobile Number with country code",
            "type": "phone_number",
            "fieldType": "phonenumber",
            "description": "Mobile number with country code",
            "groupName": "contactinformation",
            "options": [],
            "displayOrder": -1,
            "calculated": true,
            "externalOptions": false,
            "hasUniqueValue": false,
            "hidden": true,
            "hubspotDefined": true,
            "modificationMetadata": {
                "archivable": true,
                "readOnlyDefinition": true,
                "readOnlyValue": true
            },
            "formField": false
        }

 

A short section of the Python code I'm using:


from_contact_properties_response = requests.request("GET", from_contact_properties_url, headers=from_contact_properties_headers, data=from_contact_properties_payload)
from_contact_properties_data = from_contact_properties_response.json()
from_contact_properties = from_contact_properties_data['results']
to_contact_properties_inputs = []
for i in from_contact_properties:
    if i["hubspotDefined"] == True:
        print(i)
    else:
        to_contact_properties_inputs.append(i)

 

The overall response to json approach is something I've used many times before, and works fine for reading if the "name" key contains certain text, if the "fieldType" is equal to a certain value, etc.  First time trying to use logic based on the boolean fields though, and this is giving issues.  I'm hoping that I don't have to completely redo how I've been making calls and retrieving and reading requests, but if necessary I will make those adjustments. 

Thank you!

2 Accepted solutions
taran42
Solution
Contributor

Reading "hubspotDefined": true in Python

SOLVE

@klloyd__1 I'm not 100%, but maybe it's case sensitive?

 

Something else is that you could search your JSON code for the "hubspotDefined" string and then search for the value of "true" or "false."

View solution in original post

klloyd__1
Solution
Participant | Gold Partner
Participant | Gold Partner

Reading "hubspotDefined": true in Python

SOLVE

@Tara boom, that worked!  updated the code to:

 

if '"hubspotDefined: true"' in i:
        print(i)

 

as you suggested, rather than testing against the boolean value of that key, it's simply checking to see if that entire string exists within i.  This will work for what I'm looking to accomplish, thank you again!

View solution in original post

3 Replies 3
taran42
Solution
Contributor

Reading "hubspotDefined": true in Python

SOLVE

@klloyd__1 I'm not 100%, but maybe it's case sensitive?

 

Something else is that you could search your JSON code for the "hubspotDefined" string and then search for the value of "true" or "false."

klloyd__1
Solution
Participant | Gold Partner
Participant | Gold Partner

Reading "hubspotDefined": true in Python

SOLVE

@Tara boom, that worked!  updated the code to:

 

if '"hubspotDefined: true"' in i:
        print(i)

 

as you suggested, rather than testing against the boolean value of that key, it's simply checking to see if that entire string exists within i.  This will work for what I'm looking to accomplish, thank you again!

Jaycee_Lewis
Community Manager
Community Manager

Reading "hubspotDefined": true in Python

SOLVE

Hey, @klloyd__1 thanks for reaching out. I appreciate you including all those details and context. 

 

@taran42 do you have any insight into how @klloyd__1 might approach this situation?

 

Thank you 🙌 – Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes