Retrieving several fields from HubSpot API with Python - how to do it correctly?

I’m working on a Python script to fetch deal records from HubSpot and I need to get both the stage and name fields for each deal. When I try to pull just one field, everything works fine. But when I attempt to grab multiple fields at once, only the last one shows up in my results.

Here’s what I’m trying to do:

# Connection setup done above this part
api_params = {
    'hapikey': my_api_key, 
    'limit': record_limit, 
    'properties': 'deal_stage', 
    'properties': 'deal_name'
}

keep_going = True
while keep_going:
    encoded_params = urllib.parse.urlencode(api_params)
    # Additional code for pagination and data processing follows

The weird thing is that I only get the deal_name field back, even though I specified both properties. I read in the HubSpot docs that you need to add the properties parameter multiple times for each field you want, but this approach isn’t working for me. What am I missing here?

This isn’t a HubSpot API issue - it’s a Python dictionary problem. You’ve got ‘properties’ defined twice, so the second value overwrites the first. That’s why you’re only getting deal_name back. I hit this exact same thing about six months ago on a similar project. Fix is simple - pass multiple properties as a comma-separated string in one parameter: api_params = { ‘hapikey’: my_api_key, ‘limit’: record_limit, ‘properties’: ‘deal_stage,deal_name’ } Works perfectly and you’ll get both fields. HubSpot’s docs aren’t super clear on this, but comma-separated is how their REST API handles multiple properties.

yeah, i had the same issue too when i got into hubspot’s api. the problem is that your dict overwrites itself since python dont allow duplicate keys. just combine them: ‘properties’: ‘deal_stage,deal_name’ and then you’ll see both fields come through.

Had the same headache when I started with HubSpot’s API last year. You’re hitting basic Python behavior - when you declare the same dictionary key twice, Python keeps the last one and dumps the first. Your ‘properties’: ‘deal_stage’ gets completely replaced by ‘properties’: ‘deal_name’, so you’re only seeing deal names in your response. Fix is simple: combine all properties into one string with commas. Your api_params should be ‘properties’: ‘deal_stage,deal_name’. I’ve used this for over a year pulling different deal properties and it works perfectly for multiple fields. HubSpot’s docs could definitely explain this better.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.