Back to listing

Get property values from a specific record

Category:
Function

ETL:
Extract

Notes

If you're searching for objects, you can easily get the HubSpot API to respond with the values of specific properties. But, if you only know the unique ID of a record, there are many scenarios where you will need to ask HubSpot for more information. 

Perhaps you have an integration with another CRM and each platform stores the unique ID of the synchronised record. Your cron job will need to look up any changes to the properties you're synchronising. 

This function allows you to get a response from HubSpot's API for a single record. 

Code

        

Language: JavaScript



 

const accessToken = `Bearer 1234`; // You'll want to define this using a secret instead of directly in the code

 

function getPropertyDetails() {

    const objectType = "deals";

    const uniqueId = "1234";

    const urlProperties = `https://api.hubapi.com/crm/v3/objects/${objectType}/${uniqueId}`;

    const paramsProperties = {

      properties: 'property_one, property_two, property_three', // Include the properties you want to know the values of as a comma-separated list

      archived: false

    };

    const headers = {

      Authorization: accessToken

    };

    // Use direct objects for params and headers

    return axios.get(urlProperties, { params: paramsProperties, headers: headers })

      .then(response => {

      console.log(response.data);

      propertyOne = response.data.properties.property_one;

      propertyTwo = response.data.properties.property_two;

      propertyThree = response.data.properties.property_three;

      console.log('propertyOne:', propertyOne, 'propertyOne:', rccPropertyTwo, 'propertyTwo:', propertyThree);

    })

      .catch(error => {

      console.error(error); // You'll want to include more sophisticated error handling based on your specific needs

    });

  }

How can SpotDev support your business?

HubSpot Migrations

Move from Salesforce, Dynamics, Pipedrive or any CRM to HubSpot with SpotDev.

Learn more

HubSpot Integrations

Add advanced functionality to your HubSpot portal with API development services.

Learn more

RevOps

Align your sales, marketing and service teams to break down silos and trigger growth.

Learn more