> ## 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 Salesforce

> Trigger CloudTalk VoiceAgent calls directly from Salesforce using Flow Builder and an Apex HTTP callout

> [!NOTE]
>
> You can automatically trigger a CloudTalk VoiceAgent call from Salesforce using Flow Builder with an HTTP Callout, backed by an Apex class. This guide shows you how to set up the connection, add the call action, and confirm the call was initiated.

**User level:** Admin

***

## Before you start

You will need:

* A CloudTalk VoiceAgent already created (note the VoiceAgent ID)

* [CloudTalk API credentials](https://help.cloudtalk.io/en/articles/15272380-how-to-access-and-generate-your-cloudtalk-api-keys.md) (API Key and Secret)

* Salesforce Enterprise edition or above (Flow Builder with HTTP Callout)

* A phone field available on your Contact or Lead records, in `E.164` format (for example, `+14155550100`)

## Set up the integration

### Create the Named Credential

First, create an External Credential to store your CloudTalk API key securely:

1. Go to **Setup > Security > Named Credentials > External Credentials**.

2. Click **New External Credential**:

   * **Label:** CloudTalk API

   * **Name:** CloudTalk\_API

   * **Authentication Protocol:** Basic

   ![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/f42afbda40a0-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=9aa5faa95041ed98f83abc78b33f4f9c)

3. Click **Save**, then under **Principals** click **New**:

   * Choose a name and set **Identity Type** to **Named Principal**.

   * Enter your CloudTalk **API Key ID** as the username and **API Secret** as the password.

   * Click **Save**.

![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/80d0479bd0d9-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=2bc7d38895a1ff4a48d88726ddb32479)

Next, create the Named Credential that points to CloudTalk:

1. Go to **Setup > Security > Named Credentials > Named Credentials**.

2. Click **New Named Credential**:

   * **Label:** CloudTalk

   * **Name:** CloudTalk

   * **URL:** `https://api.cloudtalk.io`

   * **External Credential:** CloudTalk API

   * Under **Callout Options**, enable **Generate Authorization Header** and **Allow Formulas in HTTP Body**.

3. Click **Save**.

Finally, grant yourself access to the credential:

1. Go to **Setup > Permission Sets**, open (or create) a permission set assigned to you, then go to **External Credential Principal Access > Edit**, add your `CloudTalk_API` principal, and **Save**.

![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/3714caae4af3-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=3a0b3aa65e24b50345d6613885bb28fc)

![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/f22a61ebe097-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=e91164bb89d61a0ec4f33a675a6b2775)

![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/c3209907f03c-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=c24c2ae14f775dec4986bc5ef012b629)

### Create the Apex class

1. Go to **Setup > Apex Classes > New**.

2. Paste the code below, replace `YOUR_VOICE_AGENT_ID` on line 3 with your VoiceAgent ID, and **Save**.

```
public with sharing class CloudTalkVoiceAgent {

    private static final String VOICE_AGENT_ID = 'YOUR_VOICE_AGENT_ID';

    @InvocableMethod(label='Start CloudTalk Voice Agent Call' description='Triggers a CloudTalk voice agent call')
    public static void invoke(List<Request> requests) {
        for (Request r : requests) {
            startCall(r.callNumber);
        }
    }

    @future(callout=true)
    public static void startCall(String callNumber) {
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:CloudTalk/v1/voice-agent/calls');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setBody(JSON.serialize(new Map<String, Object>{
            'call_number'    => callNumber,
            'voice_agent_id' => VOICE_AGENT_ID
        }));
        HttpResponse res = new Http().send(req);
        System.debug('CloudTalk status: ' + res.getStatusCode());
    }

    public class Request {
        @InvocableVariable(label='Call Number' required=true)
        public String callNumber;
    }
}
```

### Build the Flow

1. Go to **Setup > Process Automation > Flows > New Flow**.

2. Select **Record-Triggered Flow**.

3. Configure the trigger (Object: Contact or Lead; When: a record is created or a field changes).

4. Add a condition to filter records, for example only when the phone field is not empty.

5. Click **+ > Action** and search for "Start CloudTalk Voice Agent Call".

6. Set the **Call Number** input value to `{!$Record.Phone}`.

7. Click **Save** and **Activate** the Flow.

![](https://mintcdn.com/cloudtalk/8FCfL6QWpEnHvO8c/images/help-center/articles/16064425/be2af2a8b68a-image.png?fit=max\&auto=format\&n=8FCfL6QWpEnHvO8c\&q=85\&s=3cb9bb48204255b2c370e1710c2691b2)

> [!WARNING]
>
> `call_number` and `voice_agent_id` are the only required fields. You can optionally add `call_properties`, such as system prompt variables (data the VoiceAgent uses during the call) and output variables (data passed back to your endpoint after the call), depending on your VoiceAgent configuration. [Learn what to include](https://help.cloudtalk.io/en/articles/11401649-voiceagents-for-outbound-calls.md).

### Test and verify

1. Create or update a record that meets your trigger conditions.

2. Check **Setup > Debug Logs** or the Flow interview details for execution.

3. Confirm in CloudTalk that the VoiceAgent call was initiated.

**You're all set!** 🚀 Your Salesforce Flow will now automatically trigger a CloudTalk VoiceAgent call whenever a record meets your chosen conditions.

## Troubleshooting

* **Unauthorized callout:** ensure `api.cloudtalk.io` is added in Remote Site Settings.

* **401 Unauthorized:** verify the credentials stored in the External Credential principal.

* **400 Bad Request:** confirm the phone number is in E.164 format (for example, `+14155550100`).

* **Flow not triggering:** confirm the record satisfies all entry conditions and the Flow is active.

***

Need help or have a question? 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.