Getting Specific Contact Property

I am trying to get the “city” property for all emails, but it never shows up in my result dictionary. Any idea for what needs to be added or modified?

import requests
import json
import urllib

max_results = 50 
hapikey = 'XXX' 
count = 5 
contact_list = []
property_list = ["city"]
get_all_contacts_url = "http://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=XXX&property=city"
headers = {}

# Paginate your request using offset
has_more = True
while has_more:
	parameters = urllib.parse.urlencode(parameter_dict)
	get_url = get_all_contacts_url + parameters
	r = requests.get(url= get_url, headers = headers)
	response_dict = json.loads(r.text)
	has_more = response_dict['has-more']
	contact_list.extend(response_dict['contacts'])
	parameter_dict['vidOffset']= response_dict['vid-offset']
	if len(contact_list) >= max_results: # Exit pagination, based on whatever value you've set your max results variable to. 
		print('maximum number of results exceeded')
		break
print('loop finished')

list_length = len(contact_list) 

print("You've succesfully parsed through {} contact records and added them to a list".format(list_length))

@lsignori ,

The URL is structured properly other than you are using http instead of https.

I am not a python person. @taran42 , do you see anything out of place?

@lsignori , is there a reason you are using the v1 endpoint rather than the newer v3?

@dennisedsonthank you! I used version 3 and it worked:

pip install --upgrade hubspot-api-client

import hubspot
from pprint import pprint
from hubspot.crm.contacts import ApiException

client = hubspot.Client.create(api_key="xxx")

try:
 api_response = client.crm.contacts.basic_api.get_page(limit=10, properties=["city"], archived=False)
 pprint(api_response)
except ApiException as e:
 print("Exception when calling basic_api->get_page: %s\n" % e)