Enhance your user segmentation in Usetiful by syncing HubSpot contact properties as tags. This allows you to dynamically send data such as company, country, or employment role from HubSpot to Usetiful, ensuring your customer onboarding and engagement strategies stay personalized.
1. Request API Credentials
To enable HubSpot integration, contact our support team to request API credentials.
2. Set Up a Workflow in HubSpot
- Log in to your HubSpot account and navigate to Automation -> Workflows.
- Click Create Workflow and select Start from Scratch.
- Choose Contact-based as the workflow type.
- In the Trigger panel:
- Select When filter criteria is met.
- From the object options, choose Contact properties.
- Select one or more contact properties (e.g., company, country, or employment role) that you want to convert into tags in Usetiful. Add as many criteria as needed to tailor the tags for your users.
3. Add Custom Code Action
- Click the + icon to add an action to your workflow.
- In the right panel, select Custom Code.
- Include contact properties (e.g., email, company, or country) in your code by selecting them from the Choose Property. Note: The Email property is mandatory.
4. Add the Code for Usetiful API
Once you receive the credentials, you can replace the your-service-credential
and your-password
placeholders in the code with the actual values.
exports.main = async (event, callback) => {
// Retrieve input fields from the workflow
const userId = event.inputFields['email'];
const company = event.inputFields['company'];
const country = event.inputFields['country'];
const tags = [];
// Add company tag if it's set
if (company) {
tags.push({
key: "company",
value: company
});
}
// Add country tag if it's set
if (country) {
tags.push({
key: "country",
value: country
});
}
if (tags.length > 0) {
try {
// Step 1: Get the access token
const authResponse = await fetch('https://www.usetiful.com/api-auth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
username: 'your-service-credentials',
password: 'your-password',
app: 'progressor'
})
});
const authData = await authResponse.json();
const accessToken = authData.access_token;
// Step 2: Use the token to call the tag API
const userResponse = await fetch('https://progressor.usetiful.com/api/v1/tag', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
userId: userId,
tags: tags
})
});
// Check if the user creation was successful
if (userResponse.ok) {
callback({
outputFields: {
status: 'Tags are added successfully',
userId: userId,
tags: tags
}
});
} else {
const errorData = await userResponse.json();
callback({
outputFields: {
status: 'Failed to add tags',
errorMessage: errorData.message || 'Unknown error'
}
});
}
} catch (error) {
callback({
outputFields: {
status: 'Failed to add tags',
errorMessage: error.message
}
});
}
}
};
5. Test and Publish
- Test the custom code action to make sure it works correctly.
- Once the test is successful, publish the workflow to activate it.