> ## Documentation Index
> Fetch the complete documentation index at: https://help.cloudtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Triggering a VoiceAgent Call from a HubSpot

> Automate VoiceAgent calls from HubSpot

> [!NOTE]
>
> You can automatically trigger a CloudTalk VoiceAgent call using HubSpot Workflows. This guide shows you how to set up the trigger, pass contact data into CloudTalk, and view enrollment results in HubSpot.

**User level**: Agent

***

## Before you start

You will need:

* A CloudTalk VoiceAgent already created

* CloudTalk API credentials (API Key and Secret)

* A HubSpot account with access to Workflows

* Contact properties that include at least a phone number

## Create a HubSpot Workflow Trigger

1. Open **HubSpot > Workflows**.

2. Create a new **Contact-based** workflow.

3. Choose a trigger type, for example:

   * Property value changed

   * List membership changed\
     (Custom fields are also supported.)

     ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/c4ac4d6f7232-ac305f92-e12b-494c-89fc-91ba05aae470.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=429126c1623fa5c9adbec1e22396ec7d)

4. **Optional**: Enable **Re-enrollment** if you want the same contact to be called multiple times whenever the conditions are met.

   ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/22e29be7058c-be9c1a46-091b-47af-8df6-0a6091fa4ee6.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=0927b748b552f2c34ba4b806cb8b2e30)

## Add the Custom Code Action

After setting your trigger:

1. Click **`+ Add action`**

2. Select **Data ops > Custom code**

3. Configure the action:

   * **Language:** Node.js 20.x

   * **Secrets:** Leave empty

   * **Properties to include in code:**

     * `phone` (required)

     * Additional fields as needed, such as `name` or `contactId`

These properties become `event.inputFields[...]` inside the script.

## Paste the Code Snippet

```
const axios = require('axios');
exports.main = async (event, callback) => {
  const phone = event.inputFields['phone'];
  const name = event.inputFields['name'];
  const contactId = event.inputFields['contactId'];

  try {
    // Convert hs_object_id to integer
    const contactIDint = parseInt(contactId, 10);

    // Check if conversion was successful
    if (isNaN(contactIDint)) {
      throw new Error('Invalid hs_object_id: not a number');
    }

    // Prepare request body
    const data = {
      call_number: phone,
      voice_agent_id: "67eba86558ba995b89e05e08",
      call_properties: {
        system_prompt: {
          variables: {
            name: name
          }
        },
        output: {
          variables: {
            contactID: contactIDint
          }
        }
      }
    };

    // Send POST request
    const response = await axios.post('https://api.cloudtalk.io/v1/voice-agent/calls', data, {
      headers: {
        'Authorization': 'Basic #{{ Auth Header}}',
        'Content-Type': 'application/json'
      }
    });

    // Log success and return
    console.log('Call triggered successfully:', response.data);
    callback({
      outputFields: {
        status: 'Call triggered successfully'
      }
    });
  } catch (error) {
    console.error('Error triggering call:', error.message);
    callback({
      outputFields: {
        status: `Error: ${error.message}`
      }
    });
  }
};
```

**This script**:

* Sends a POST request to the CloudTalk VoiceAgent API

* Passes the contact’s phone number

* Optionally passes variables such as first name or Record ID

* Receives the VoiceAgent output back to your selected endpoint in CloudTalk

![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/d6dc73b07298-ea61f21c-4b9e-4d5c-883c-94d1f7999db5.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=0aed37a6d3a2329b6c24c194183c154b)

![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/de0c9a325618-17e3a91a-4a9a-468b-b2ba-d6d438f22c59.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=d14cc096ce5e933090c2a6b897905a47)

## Generate the Authorization Header

CloudTalk uses Basic Authentication for API requests.\
To generate your encoded value:

1. Go to **[https://www.debugbear.com/basic-auth-header-generator](https://www.debugbear.com/basic-auth-header-generator)**

2. Enter your **CloudTalk API Key** and **CloudTalk API Secret**\
   (found in your CloudTalk **Company Settings**).

3. Copy the generated header. It will look similar to: `Basic XXXXXXXXX`

Replace `#{{ Auth Header }}` in the script with this value.

## Publish and Test the Workflow

1. Save the custom code step.

2. Click **Review and publish**.

3. Decide whether the workflow should:

   * Only run for new contacts matching conditions, or

   * Also run for contacts that already match when the workflow is activated.

4. Trigger the workflow by updating a property or list membership for a test contact.

![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/9777bd45a442-47bb8f60-4eba-4ecd-b203-c564b0c0599d.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=e325692b9a1ac50a54d5b4fce972dbd9)

## Check Enrollment History

To confirm your VoiceAgent call was triggered:

1. Open the workflow

2. Go to **Performance history > Enrollment history**

3. Find your test contact in the list

   ![](https://mintcdn.com/cloudtalk/Ql3WX5wAKbGZniqk/images/help-center/articles/12858495/ed8dc31c3922-6252a13d-076e-409e-8b0c-471d702ca1d4.png?fit=max\&auto=format\&n=Ql3WX5wAKbGZniqk\&q=85\&s=f8d6c6b27a336480557c6a6a131693d9)

You should see the contact enrolled and the action **Call triggered successfully** if everything worked.

**You're all set!**

Your HubSpot workflow will now automatically trigger a CloudTalk VoiceAgent call whenever a contact meets your chosen conditions.

***

*Need help or have a question?* Just reach out through our [Support portal](https://support.cloudtalk.io/hc/en-us/requests/new?ticket_form_id=26305535257884) — we’re here for you.


## Related topics

- [Triggering a VoiceAgent Call from Freshdesk](https://help.cloudtalk.io/en/articles/15457387-triggering-a-voiceagent-call-from-freshdesk.md)
- [Triggering a VoiceAgent Call from Zendesk](https://help.cloudtalk.io/en/articles/15934846-triggering-a-voiceagent-call-from-zendesk.md)
- [Triggering a VoiceAgent Call from Freshservice](https://help.cloudtalk.io/en/articles/15502021-triggering-a-voiceagent-call-from-freshservice.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.