HubSpot/hubspot-api-nodejs

Question | How to get all notes for a specific deal with the info (property) which deal is pinned

natterstefan opened this issue · 8 comments

Dear maintainers and contributors,

can you please share an example for the use case as per the issue title?

Thank you very much for your time and help.

Hi @natterstefan .
The SDK version: 10.1.0
Workable example:

require('dotenv').config({ path: '.env' })

const hubspot = require('@hubspot/api-client')

const hubspotClient = new hubspot.Client({ accessToken: process.env.HUBSPOT_PRIVATE_APP_ACCESS_TOKEN })

async function main() {
  let deal = await hubspotClient.crm.deals.basicApi.getById('14429065034', undefined, undefined, ['notes']);
  console.log(deal.associations?.notes?.results)

  if (deal.associations?.notes != undefined) {
    let inputs = [];
    for(const association of deal.associations?.notes.results) {
      console.log(association.id)
      inputs.push({'id': association.id})
    }

    const notes = await hubspotClient.crm.objects.notes.batchApi.read({inputs, properties: ['hs_body_preview']}, false);
    console.log(notes);
  }
}

main();

Hi @ksvirkou-hubspot,

thanks for sharing a workable example. Very kind of you. What about this request in the issue title "with the info (property) which deal is pinned"? Is this possible? How can I filter by pinned notes? They are valuable in the UI on Hubspot, but I see no way of getting them per API...

In Hubspot you can associate objects and associated objects have no pinned property.
You can read more in the docs.

For filtering by associated notes you can use method hubspotClient.crm.objects.notes.searchApi.doSearch(request).
You can read more in Search docs and Notes docs.
Workable example:

async function main() {
  let deal = await hubspotClient.crm.deals.basicApi.getById('14355896864', undefined, undefined, ['notes']);
  console.log(deal.associations?.notes?.results)

  if (deal.associations?.notes != undefined) {
    let associatedNotes = [];
    for(const association of deal.associations?.notes.results) {
      console.log(association.id)
      associatedNotes.push(association.id)
    }
    const request = {
      properties: ["hs_body_preview"],
      filterGroups: [
        {
          filters:[
            {
              propertyName: "id",
              values: associatedNotes,
              operator: "IN"
            },
            {
              propertyName: "hs_body_preview",
              value: "Note1",
              operator: "EQ"
            }
          ]
        }
      ]
    };
    const notes = await hubspotClient.crm.objects.notes.searchApi.doSearch(request);
    console.log(notes);
  }
}

Hi @ksvirkou-hubspot,

thanks for sharing another valuable example. But that does not give me a way to get the pinned associated note, correct?

The first example get all associated notes.
The second example search for note witch text Note1 in all associated notes.

Hi @natterstefan .
You can get pinned object id by this way:

 let deal = await hubspotClient.crm.deals.basicApi.getById('14355896864', ['hs_pinned_engagement_id']);

  if (deal.properties.hs_pinned_engagement_id != undefined) {
    llet note = await hubspotClient.crm.objects.notes.basicApi.getById(deal.properties.hs_pinned_engagement_id);
    console.log(note)
  }

if you don't know type of pinned id you can get it by this way:

 let deal = await hubspotClient.crm.deals.basicApi.getById('14355896864', ['hs_pinned_engagement_id'], undefined, ['notes']);
  console.log(deal)

  if (deal.properties.hs_pinned_engagement_id != undefined) {
    let engagement = await hubspotClient.crm.objects.basicApi.getById('engagement', deal.properties.hs_pinned_engagement_id, ['hs_engagement_type']);
    console.log(engagement)
  }