Integrate HubSpot's workflows with Usetiful to create personalized user experiences effortlessly. Here's a step-by-step guide,

Before You Begin

  • Log in to your Usetiful account.
  • Navigate to the Integrations page and activate the HubSpot integration to connect it with Usetiful.


1. Request API Credentials

To enable HubSpot integration with Usetiful, you need API credentials. Contact our support team to request these credentials.

2. Set Up a workflow in HubSpot

Follow these steps to create a workflow for Usetiful integration:

  • Log in to your HubSpot account and go to Automation -> Workflows.



  • Click Create Workflow and select Start From Scratch.
  • Choose Contact-based as the workflow type and click Next.
  • In the Set up triggers panel, select When an event occurs.
  • From the CRM section, choose Object Created and Save.


3. Add Custom Code Action

  • Click the + icon in your workflow to add an action.




  • In the left panel, select Custom Code.
  • Include properties in your code by selecting them.



  • Add the API credentials to the Custom Code action in your HubSpot workflow. You will need to request the API credentials from the Usetiful team. These credentials are necessary to authenticate your requests and interact with the 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) => {
  const userId = event.inputFields['email']; // Get the email property. It's required
  const firstName = event.inputFields['firstName']; // Get the first name property. It's optional
  const lastName = event.inputFields['lastName']; // Get the last name property. It's optional
  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-credential',
       password: "your-password",
       app: 'progressor'
  })
  });

  const authData = await authResponse.json();
  const accessToken = authData.access_token;
    
  // Step 2: Use the token to call the user API
  const userResponse = await fetch('https://progressor.usetiful.com/api/v1/user', {
  method: 'POST',
  headers: {
       'Authorization': `Bearer ${accessToken}`,
       'Content-Type': 'application/json',
       'Accept': 'application/json'
  },
  body: JSON.stringify({
       userId: userId,
       firstName: firstName, // optional
       lastName: lastName // optional
  })
  });

  // Check if the user creation was successful
  if (userResponse.ok) {
  callback({
       outputFields: {
            status: 'User created successfully',
            userId: userId,
            firstName: firstName,
            lastName: lastName
       }
  });
  } else {
  const errorData = await userResponse.json();
  callback({
       outputFields: {
            status: 'Failed to create user',
            errorMessage: errorData.message || 'Unknown error'
       }
  });
  }

  } catch (error) {
  callback({
  outputFields: {
       status: 'Failed to create user',
       errorMessage: error.message
  }
  });
  }
};

4. Test Your Workflow.

Before activating the workflow, Test the action to ensure everything works as expected. For more information please click here.


5. Review and Publish

When the test is successful, go ahead and publish the workflow to activate it.


To learn how to sync contact properties as tags with HubSpot and Usetiful, click here.

To learn how to sync user activity with HubSpot and Usetiful, click here.