Hi,
I am trying to create a custom action in Husbpot to pull the content of logged calls. I was able to create a custom action to get contact notes from Hubspot, but I can’t seem to do it for the calls themselves.
Just for reference, here is the code to retrieve up to 10 notes associated with a contact in Hubspot. Maybe it’s possible to adjust this code to make it work for the logged calls as well? The AI agent that helps to write this was not able to adjust it, and I tried to change it manually with no luck:
// TypeScript function to get up to 10 notes associated with a specific contact and combine them into one long string
export async function getContactNotes({ contactId }: { contactId: string }): Promise<{ result: string }> {
// Step 1: Get the contact with associated note IDs
const contactUrl = `https://api.hubapi.com/crm/v3/objects/contacts/${contactId}?associations=notes`;
// Fetch the contact data with associated notes
const contactResponse = await fetchWithZapier(contactUrl);
await contactResponse.throwErrorIfNotOk();
const contactData = await contactResponse.json();
// Extract note IDs from associations, limiting to 10
const noteIds = contactData.associations?.notes?.results?.slice(0, 10).map((note: any) => note.id) || [];
// If no notes are associated, return an empty string
if (noteIds.length === 0) {
return { result: '' };
}
// Step 2: Batch read up to 10 notes to get their content
const batchUrl = 'https://api.hubapi.com/crm/v3/objects/notes/batch/read';
// Prepare the request to batch read notes
const batchResponse = await fetchWithZapier(batchUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
inputs: noteIds.map((id: string) => ({ id })),
properties: ['hs_note_body']
})
});
// Ensure the batch request was successful
await batchResponse.throwErrorIfNotOk();
const notesData = await batchResponse.json();
// Combine all note bodies into a single string
const combinedNotes = notesData.results
.map((note: any) => note.properties.hs_note_body)
.join(' ');
// Return the combined notes as a single string
return { result: combinedNotes };
}




