APIs & Integrations

SMukherjee9
Participant

How to download specific fields for every contact

SOLVE

Hello All,

 

I am trying to create an API integration with Hubspot using Python via a Private App.

 

Was able to successfully Hit the API and get back contacts data but output shows only few fields.

Here is my code so far:
from hubspot import HubSpot
from hubspot.crm.objects import ApiException

api_client = HubSpot()
api_client.access_token = '***-***-********-****-****-****-************'
try:
    all_contacts = api_client.crm.contacts.get_all()
    for itm in all_contacts:
        print(itm)
except ApiException as e:
    print("Exception when requesting custom objects: %s\n" % e)

Output JSON has only 13 fields, I need to see 57 fields.

Any inputs/tips/help in solving this will really be much appriciated.

0 Upvotes
2 Accepted solutions
LewTalon
Solution
Participant | Partner
Participant | Partner

How to download specific fields for every contact

SOLVE

 

You can specify the properties returned in the response by adding them to the request. 

 

You can add an array "properties=[]" and specify which properties. In this case I've added "Test Property" but you can add multiple 

try:
api_response = client.crm.contacts.default_api.get_page(limit=10, properties=["test property", "another test property"], archived=False)

 Then when you make the request you'll get the data for each property added. Hope this helps!

View solution in original post

LewTalon
Solution
Participant | Partner
Participant | Partner

How to download specific fields for every contact

SOLVE

@SMukherjee9  Glad I helped answer the question.

 

In order to retrieve all properties, you will need to include them all within that array.

 

In order to format the request quickly you can just use this endpoint (it's the same one you mentioned but a newer version)

 

url = "https://api.hubapi.com/crm/v3/properties/contacts"

This will give you a full list of all the properties in the system (an internal list, not the values on the specific record.) Then you can use something like JSON to CSV (or create a script to just get the "name" value. (something like results.name[0] for each result in the array.) This will give you a full list of all the properties internal name.

 

Then you can add those all to the initial request, and you'll get a list of all the properties for that specific contact. 

 

Also, note that the response you sent indicates Invalid Authentication - this means your access token is invalid. You should be able to get it within your private app. 

 

Feel free to DM me if you need any help. 

View solution in original post

4 Replies 4
LewTalon
Solution
Participant | Partner
Participant | Partner

How to download specific fields for every contact

SOLVE

 

You can specify the properties returned in the response by adding them to the request. 

 

You can add an array "properties=[]" and specify which properties. In this case I've added "Test Property" but you can add multiple 

try:
api_response = client.crm.contacts.default_api.get_page(limit=10, properties=["test property", "another test property"], archived=False)

 Then when you make the request you'll get the data for each property added. Hope this helps!

SMukherjee9
Participant

How to download specific fields for every contact

SOLVE

Hi @LewTalon - Thanks a ton for the input! 😊 It worked!
However, I need help seeing specific properties due to my limited understanding of this platform. Is there a way by which I can see all the properties of a contact ( both default and custom )? I tried this from the documentation but only got an Invalid API error. In the previous case, the API key is working perfectly fine.

From Documentation:
https://legacydocs.hubspot.com/docs/methods/contacts/v2/get_contacts_properties

My Code:

import requests

url = "https://api.hubapi.com/properties/v1/contacts/properties"
querystring = {'hapikey': 'Bearer ***-***-********-****-****-****-************'}

response = requests.request("GET", url, params=querystring)
print(response.text)

Output:

{"status":"error","message":"The API key provided is invalid. View or manage your API key here: https://app.hubspot.com/l/api-key/","correlationId":"********-****-****-****-************","category":"INVALID_AUTHENTICATION","links":{"api key":"https://app.hubspot.com/l/api-key/"}}

0 Upvotes
LewTalon
Solution
Participant | Partner
Participant | Partner

How to download specific fields for every contact

SOLVE

@SMukherjee9  Glad I helped answer the question.

 

In order to retrieve all properties, you will need to include them all within that array.

 

In order to format the request quickly you can just use this endpoint (it's the same one you mentioned but a newer version)

 

url = "https://api.hubapi.com/crm/v3/properties/contacts"

This will give you a full list of all the properties in the system (an internal list, not the values on the specific record.) Then you can use something like JSON to CSV (or create a script to just get the "name" value. (something like results.name[0] for each result in the array.) This will give you a full list of all the properties internal name.

 

Then you can add those all to the initial request, and you'll get a list of all the properties for that specific contact. 

 

Also, note that the response you sent indicates Invalid Authentication - this means your access token is invalid. You should be able to get it within your private app. 

 

Feel free to DM me if you need any help. 

SMukherjee9
Participant

How to download specific fields for every contact

SOLVE

Thanks again @LewTalon!! 😊🔥🔥