Unable to get ids from externalcontacts API in Python or convert to json

Been using this api to get all the external ids in the org but I been having trouble trying to select all of them.
/api/v2/externalcontacts/contacts

However, I been unable to convert it successfully to a json object or grab all the ids I need.
I can access all the way to entities but it won't let me convert to json and when I sort them I can't get the 'id' key needed. Any recommendation on how to grab all the external contact ids from the results?

Api_resonse is the object/list returned from the api for python.

api_response.entities

I'm trying to get the ids for the contacts but it doesn't let me go further then entities in the object returned.

[{'address': None,
'canonical_contact': None,
'cell_phone': {'accepts_sms': False,
'country_code': None,
'display': '+XXXXXXXXXX',
'e164': None,
'extension': None,
'user_input': '+XXXXXXXXX'},
'create_date': datetime.datetime(2023, 8, 30, 18, 45, 1, tzinfo=tzutc()),
'custom_fields': None,
'external_data_sources': None,
'external_organization': None,
'external_system_url': None,

}

'external_data_sources': None,
'external_organization': None,
'external_system_url': None,
'facebook_id': None,
'first_name': 'XXXX',
'home_phone': None,
'id': 'XXXXXXX',
'last_name': 'XXXXX',
'line_id': None,
'merge_operation': None,
'merge_set': None,
'middle_name': None,
'modify_date': datetime.datetime(2021, 8, 16, 18, 35, 2, tzinfo=tzutc()),
'other_email': None,
'other_phone': None,
'personal_email': None,
'salutation': None,
'schema': None,
'self_uri': '/api/v2/externalcontacts/contacts/XXXXXXXXXXXX,
'survey_opt_out': None,
'title': None,
'twitter_id': None,
'type': 'Curated',
'whats_app_id': None,
'work_email': None,
'work_phone': None},

Hello,

entities is Python list.

You can loop through the elements with something like this:

for excontact in api_response.entities:
  print(excontact.id)

Regards,

1 Like

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