APIs & Integrations

RCoronel
Participant

Extra properties contacts.get_all()

SOLVE

When executing this code: 

 

contacts_fetched = api_client.crm.contacts.get_all()

 

The response is the following

 

'id': '15251',
 'properties': {'createdate': '2023-02-24T06:55:51.430Z',
                'email': 'emailmaria@hubspot.com',
                'firstname': 'Maria',
                'hs_object_id': '15251',
                'lastmodifieddate': '2023-02-24T06:55:58.246Z',
                'lastname': 'Johnson (Sample Contact)'},
 'properties_with_history': None,
 'updated_at': datetime.datetime(2023, 2, 24, 6, 55, 58, 246000, tzinfo=tzutc())}, {'archived': False,
 'archived_at': None,
 'associations': None,
 'created_at': datetime.datetime(2023, 2, 24, 7, 0, 9, 664000, tzinfo=tzutc()),

 

I need to add the phone number, website, and other custom properties to the properties retrieved.
but currently I cant find a way to do it in the publicly available documentation, does anybody have a way to solve it, there is old post that just add it to the parameters of the URL with something like:

 

https://api.hubspot.com/crm/v3/objects/contacts?properties=email&associations=companies

 

 

but I'm not sure how to use this with the current Hubspot library, and when I try to use it like a regular API it returns a 401 Http Error

0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

Extra properties contacts.get_all()

SOLVE

Hi, @RCoronel 👋 I'm going to assume you are using the CRM API | Contacts. Let's try by using the provided example listed here — GET /crm/v3/objects/contacts

  • For my test we'll add three additional properties — Phone number (default), website URL (default), and Ultimate Pet (a custom property)
  • You'll format the request like this:
    import hubspot
    from pprint import pprint
    from hubspot.crm.contacts import ApiException
    
    client = hubspot.Client.create(access_token="YOUR_ACCESS_TOKEN")
    
    try:
        api_response = client.crm.contacts.basic_api.get_page(limit=3, properties=["phone,website,ultimate_pet"], archived=False)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling basic_api->get_page: %s\n" % e)

    I set the limit at 3, but you can set it to a value that is appropriate for your needs

  • Response that includes our additional responses:
    HTTP 200
    
    {
      "results": [
        {
          "id": "1",
          "properties": {
            "createdate": "2022-06-29T17:59:00.693Z",
            "hs_object_id": "1",
            "lastmodifieddate": "2023-03-02T18:54:43.626Z",
            "phone": "+15055555555",
            "ultimate_pet": "Bird",
            "website": "http://www.HubSpot.com"
          },
          "createdAt": "2022-06-29T17:59:00.693Z",
          "updatedAt": "2023-03-02T18:54:43.626Z",
          "archived": false
        },
        {
          "id": "51",
          "properties": {
            "createdate": "2022-06-29T17:59:01.172Z",
            "hs_object_id": "51",
            "lastmodifieddate": "2023-03-02T18:55:07.932Z",
            "phone": "+15055555555",
            "ultimate_pet": "Dog",
            "website": "http://www.HubSpot.com"
          },
          "createdAt": "2022-06-29T17:59:01.172Z",
          "updatedAt": "2023-03-02T18:55:07.932Z",
          "archived": false
        },
        {
          "id": "101",
          "properties": {
            "createdate": "2022-06-30T04:07:35.653Z",
            "hs_object_id": "101",
            "lastmodifieddate": "2023-03-02T18:54:19.926Z",
            "phone": "+15055555555",
            "ultimate_pet": "Cat",
            "website": "http://hubspot.com"
          },
          "createdAt": "2022-06-30T04:07:35.653Z",
          "updatedAt": "2023-03-02T18:54:19.926Z",
          "archived": false
        }
      ],
      "paging": {
        "next": {
          "after": "102",
          "link": "https://api.hubapi.com/crm/v3/objects/contacts?hs_static_app=endpoint-reference-ui&hs_static_app_version=1.2125&limit=3&properties=phone%2Cwebsite%2Cultimate_pet&archived=false&after=102"
        }
      }
    }​
  • My suggestion is to try using the endpoint and example listed in the documentation, and run a few quick tests. This should help clarify how the formatting will look for your request.

Have fun building! — Jaycee

 


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !

View solution in original post

3 Replies 3
Jaycee_Lewis
Solution
Community Manager
Community Manager

Extra properties contacts.get_all()

SOLVE

Hi, @RCoronel 👋 I'm going to assume you are using the CRM API | Contacts. Let's try by using the provided example listed here — GET /crm/v3/objects/contacts

  • For my test we'll add three additional properties — Phone number (default), website URL (default), and Ultimate Pet (a custom property)
  • You'll format the request like this:
    import hubspot
    from pprint import pprint
    from hubspot.crm.contacts import ApiException
    
    client = hubspot.Client.create(access_token="YOUR_ACCESS_TOKEN")
    
    try:
        api_response = client.crm.contacts.basic_api.get_page(limit=3, properties=["phone,website,ultimate_pet"], archived=False)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling basic_api->get_page: %s\n" % e)

    I set the limit at 3, but you can set it to a value that is appropriate for your needs

  • Response that includes our additional responses:
    HTTP 200
    
    {
      "results": [
        {
          "id": "1",
          "properties": {
            "createdate": "2022-06-29T17:59:00.693Z",
            "hs_object_id": "1",
            "lastmodifieddate": "2023-03-02T18:54:43.626Z",
            "phone": "+15055555555",
            "ultimate_pet": "Bird",
            "website": "http://www.HubSpot.com"
          },
          "createdAt": "2022-06-29T17:59:00.693Z",
          "updatedAt": "2023-03-02T18:54:43.626Z",
          "archived": false
        },
        {
          "id": "51",
          "properties": {
            "createdate": "2022-06-29T17:59:01.172Z",
            "hs_object_id": "51",
            "lastmodifieddate": "2023-03-02T18:55:07.932Z",
            "phone": "+15055555555",
            "ultimate_pet": "Dog",
            "website": "http://www.HubSpot.com"
          },
          "createdAt": "2022-06-29T17:59:01.172Z",
          "updatedAt": "2023-03-02T18:55:07.932Z",
          "archived": false
        },
        {
          "id": "101",
          "properties": {
            "createdate": "2022-06-30T04:07:35.653Z",
            "hs_object_id": "101",
            "lastmodifieddate": "2023-03-02T18:54:19.926Z",
            "phone": "+15055555555",
            "ultimate_pet": "Cat",
            "website": "http://hubspot.com"
          },
          "createdAt": "2022-06-30T04:07:35.653Z",
          "updatedAt": "2023-03-02T18:54:19.926Z",
          "archived": false
        }
      ],
      "paging": {
        "next": {
          "after": "102",
          "link": "https://api.hubapi.com/crm/v3/objects/contacts?hs_static_app=endpoint-reference-ui&hs_static_app_version=1.2125&limit=3&properties=phone%2Cwebsite%2Cultimate_pet&archived=false&after=102"
        }
      }
    }​
  • My suggestion is to try using the endpoint and example listed in the documentation, and run a few quick tests. This should help clarify how the formatting will look for your request.

Have fun building! — Jaycee

 


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !
RCoronel
Participant

Extra properties contacts.get_all()

SOLVE

thanks @Jaycee_Lewis that help a lot but now its truncating some of the responses, a get close to 200 contacts without any relevant property only:
'createdate'
'hs_object_id'
'lastmodifieddate'


0 Upvotes
RCoronel
Participant

Extra properties contacts.get_all()

SOLVE

thanks so much that did help, but now I have a different issue, I'm getting a truncated contact with its properties:

 

{'id': '8501', 
'properties': {
'createdate': '2020-12-31T16:55:09.398Z', 
'hs_object_id': '8501', 
'lastmodifieddate': '2023-02-23T17:48:31.971Z'}, 
'properties_with_history': None, 
'created_at': datetime.datetime(2020, 12, 31, 16, 55, 9, 398000, tzinfo=tzutc()), 'updated_at': datetime.datetime(2023, 2, 23, 17, 48, 31, 971000, tzinfo=tzutc()), 'archived': False, 'archived_at': None, 'associations': None}

 

that from this piece of code:

 

import hubspot
from hubspot.crm.contacts import ApiException

api_response = client.crm.contacts.basic_api.get_page(limit=limit, properties=["email,firstname,lastname,phone,website,company"], archived=False, after=after)

for contact in api_response:
    foo(contact)

 

and that ID corresponds with actual contact with properties in it. 

0 Upvotes