To map the hs_created_by ID from the Engagements API to the HubSpot user’s first and last name, follow these steps:
- 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.
- 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.
- 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