APIs & Integrations

aferrari7
Participant

Contacts Module - Fields

SOLVE

Hi,

I'm using python to retrive contacts data and storing into a .json file using the following code:

 

with open('contatos.json',"w", encoding='utf-8') as outfile:
for item in contact_list:
json.dump(item, outfile, ensure_ascii=False)
outfile.write('\n')

 

 

I'm reading the .json file in Qlik Sense and i notice that for the field "properties" there are more then one possible value. Actually this is not happening only for this field. 

Could this be a displacemant?

example.png

 

 

0 Upvotes
1 Accepted solution
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Contacts Module - Fields

SOLVE
Hello @aferrari7

In get call of a contact, we get a detailed response from API and that includes almost all the contact properties associated with a record. In api response for getting a contact, we have a specific index for properties and then under fhis all the default as well as custom properties with label, internal name and value are listed. So in order to store contact data into a json file, you need to loop the properties index as well.

Hope it helps you.

Thanks
Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

3 Replies 3
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Contacts Module - Fields

SOLVE
Hello @aferrari7

In get call of a contact, we get a detailed response from API and that includes almost all the contact properties associated with a record. In api response for getting a contact, we have a specific index for properties and then under fhis all the default as well as custom properties with label, internal name and value are listed. So in order to store contact data into a json file, you need to loop the properties index as well.

Hope it helps you.

Thanks
Digital Marketing & Inbound Expert In Growth Hacking Technology
aferrari7
Participant

Contacts Module - Fields

SOLVE

Hi @himanshurauthan , thank's for the reply!

 

This is the code i'm using. 

import requests
import json
import urllib.parse

max_results = 22000
hapikey = '9666####-####-####-####-############' 
count = 2000
contact_list = []
property_list = []
get_all_contacts_url = "https://api.hubapi.com/contacts/v1/lists/all/contacts/all?"
parameter_dict = {'hapikey': hapikey, 'count': count}
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('Número máximo de usuário excedido')
		break
print('loop finalizado')

list_length = len(contact_list) 

print("Você analisou com êxito {} registros de contatos e os adicionou a uma lista".format(list_length))

#print(contact_list)


with open('contatos.json',"w", encoding='utf-8') as outfile:
	#Armazena o json como txt.
	for item in contact_list:
		json.dump(item, outfile, ensure_ascii=False)
		outfile.write('\n')

What i can't understand is how to call the custom properties. Could you help me understand that?

 

Ty,

 

Alisson

 

0 Upvotes
aferrari7
Participant

Contacts Module - Fields

SOLVE

Nevermind, i did it putting the customized fields in the parameter_dict

 

Ty.