Getting the first and last name of a Note's creator

I’m using the Engagements API to get a list of notes, including the hs_created_by field. This contains HubSpot user IDs like those found in the Settings > Users page within the portal, e.g. https://app.hubspot.com/settings/<instanceID>/users/user/<userID>. I would like to get the first and last name associated with this user ID.

Using the Settings/User Provisioning API Accounts Dashboard | HubSpot, the correct record is returned for a given ID, however it does not include their first or last name and I can’t see a way to request specific properties in this API.

The docs for the newer CRM Users API Accounts Dashboard | HubSpot say that it expects IDs that are different from the user ID, and I can

verify this with my data. I am unable to get a match against a note’s hs_created_by ID using this API. The Settings/User Provisioning API also doesn’t seem to provide a way to get the ID needed for the newer CRM Users API.

How can I map the note’s hs_created_by ID to the HubSpot user’s first and last name?

@km_compiler - truly a head-spinning number of different IDs in use here - owner ID, user ID and now user object ID? I looked at the API pages and was wondering if use of the idProperty form of some of the calls could help generate a unified set of information?

Steve

Thank you @SteveHTM, it is reassuring to hear that I’m not the only one a bit flummoxed by the number of different IDs!

Unfortunately the CRM Users API (which does return first and last name) does not support querying with a different idProperty like some of the other APIs, so I can’t use another property directly there.

However your idea gave me another one that I’ll try: I think I can get the user’s email address from both APIs and join the data on that key, to get from the hs_created_by to first and last name.

OK so that worked!! h/t to @SteveHTM for the idea.

I used the Settings/User Provisioning API Accounts Dashboard | HubSpot to get all users, which includes their User ID (the same one on the note) and their email address.

I used the CRM Users API Accounts Dashboard | HubSpot to get all users, including their email address and a handy property hs_searchable_calculated_name which has the user’s full name already formed (e.g. “Firstname Lastname”, what I really wanted).

Then I joined these lists on the email address, and from there I could get the full name associated with a given User ID (on a note)!

Here’s the code (using Python + Pandas to process the data): customer-success/notes/download.py at main · cal-itp/customer-success · GitHub

Hey, @km_compiler! Thank you very much for letting us know you found a solution :raising_hands: — Jaycee

Hey @km_compiler and @SteveHTM I am setting up a quick test. I believe I’m hitting the same issues as you and want to make sure that I’ve set up my requests similarly. I’ll post my examples and results here, and we can work on getting this sorted together.

Talk soon! — Jaycee

To map the hs_created_by ID from the Engagements API to the HubSpot user’s first and last name, follow these steps:

  1. Fetch the Note Data: Use the Engagements API to get a list of notes, including the hs_created_by field, which contains the HubSpot user IDs.
  2. Fetch All Users Data: Use the CRM Users API to fetch all users and their details. This will include user IDs and other properties like first and last names.
  3. Match the IDs: Match the hs_created_by ID from the notes with the corresponding user ID from the list of users obtained from the CRM Users API.

Here’s a step-by-step breakdown:

Step 1: Fetch Note Data

Make a request to the Engagements API to get the notes:

GET /engagements/v1/engagements/paged

This will give you a list of notes, including the hs_created_by field.

Step 2: Fetch All Users Data

Make a request to the CRM Users API to get all users:

GET /crm/v3/users

This will provide a list of users, including their HubSpot user IDs and their properties like first and last names.

Step 3: Match the IDs

Once you have both datasets, you can match the hs_created_by field from the notes with the user ID from the CRM Users API response.

Here is a simplified example in Python:

import requests

# Replace with your HubSpot API key
api_key = ‘YOUR_HUBSPOT_API_KEY’

# Fetch notes from the Engagements API
engagements_url = f’https://api.hubspot.com/engagements/v1/engagements/paged?hapikey={api_key}’
engagements_response = requests.get(engagements_url)
engagements_data = engagements_response.json()

# Fetch users from the CRM Users API
users_url = f’https://api.hubspot.com/crm/v3/users?hapikey={api_key}’
users_response = requests.get(users_url)
users_data = users_response.json()

# Create a mapping of user IDs to names
user_id_to_name = {}
for user in users_data[‘results’]:
user_id = user[‘id’]
first_name = user[‘firstName’]
last_name = user[‘lastName’]
user_id_to_name[user_id] = f’{first_name} {last_name}’

# Match hs_created_by IDs to user names in notes
for engagement in engagements_data[‘results’]:
creator_id = engagement[‘engagement’][‘createdBy’]
if creator_id in user_id_to_name:
print(f"Note ID: {engagement[‘engagement’][‘id’]} was created by {user_id_to_name[creator_id]}“)
else:
print(f"Note ID: {engagement[‘engagement’][‘id’]} was created by an unknown user (ID: {creator_id})”)

Key Points

  • The hs_created_by field contains the user ID.
  • The CRM Users API provides the user details, including first and last names.
  • By fetching all users and creating a mapping of user IDs to names, you can match the hs_created_by field to get the first and last names of the users who created the notes.

By following these steps, you should be able to map the hs_created_by ID from the Engagements API to the corresponding HubSpot user’s first and last names.

Cheers and Regards,

MAPK

Thanks for the reply @MAPK - but this will not work, and is the reason I originally posted this question. The user IDs returned in the hs_created_by field are different / not available in the CRM Users API.

See my solution for how I solved it: https://community.hubspot.com/t5/APIs-Integrations/Getting-the-first-and-last-name-of-a-Note-s-creator/m-p/1003706/highlight/true#M74901