Notes
If a record already exists in HubSpot, this function allows you to update its properties.
It's ideal for use alongside the `Search CRM` snippet. If your search returns a single result, this function can update the properties.
Code
Language: JavaScript
function updateObject(propertyName, propertyValue, objectType, objectId) {
const data = {
properties: {
`${propertyName}: '${propertyValue}'`
}
};
const config = {
headers: {
'Content-Type': 'application/json',
'Authorization': accessToken
}
};
axios.patch(`https://api.hubapi.com/crm/v3/objects/${objectType}/${objectId}`, data, config)
.then(response => {
console.log(`Successfully updated the ${objectType} with ID of ${objectId}. ${propertyName} is now has a value of ${propertyValue}`);
})
.catch(error => {
console.log(`Error while updating the ${objectType} with ID of ${objectId}. Received this error message from HubSpot: ${error.message}`);
});
}
How can SpotDev support your business?
HubSpot Migrations
Move from Salesforce, Dynamics, Pipedrive or any CRM to HubSpot with SpotDev.
Learn moreHubSpot Integrations
Add advanced functionality to your HubSpot portal with API development services.
Learn moreRevOps
Align your sales, marketing and service teams to break down silos and trigger growth.
Learn more