I want to use the service API to list the USER_DEFINED labels but I can’t see a way to do it. Currently, we are using Axios to make a request like shown below but we would like to get away from this.
const response = await axios.get(
‘https://api.hubapi.com/crm/v4/associations/company/contact/labels’,
{
headers: {
Authorization: `Bearer ${config.hubspotAccessToken}`,
},
}
);
Hello @BRice17
To list the user-defined labels using the HubSpot CRM API, you can make a GET request to the following endpoint.
GET /crm/v3/properties/labels
you can use the axios library to make the API request.
const axios = require('axios');
const config = {
hubspotAccessToken: 'YOUR_ACCESS_TOKEN',
};
async function getUserDefinedLabels() {
try {
const response = await axios.get(
'https://api.hubapi.com/crm/v3/properties/labels',
{
headers: {
Authorization: `Bearer ${config.hubspotAccessToken}`,
},
}
);
// The user-defined labels are available in the response.data.results array
const userDefinedLabels = response.data.results;
console.log(userDefinedLabels);
} catch (error) {
console.error('Error:', error.response.data);
}
}
getUserDefinedLabels();
replace 'YOUR_ACCESS_TOKEN' with your actual HubSpot access token.
You can filter out the user-defined labels from the response based on their source attribute, which will be set to ‘USER_DEFINED’ for user-defined labels. If you are using an older version, you may need to adjust the endpoint accordingly.
I am trying to NOT use Axios. I want to use the latest @hubspot/api-client library. That way we can not use Axios anymore. Please advise.