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

# Salesforce

> Connect your PolyAI agent to Salesforce for customer data lookup and case management.

Connect PolyAI to Salesforce to retrieve customer records, create cases, and manage data during calls. Your agent can access account information, update records, and send follow-up messages.

<Note>This integration is available from **Integrations** in Agent Studio under **CRM**.</Note>

## Prerequisites

* A Salesforce account with **administrator** access
* Access credentials for the **PolyAI Portal**

## What you'll provide to PolyAI

Once you finish the Salesforce setup below, share the following with your PolyAI representative through a secure channel:

| Credential           | Description                                                                                 |
| -------------------- | ------------------------------------------------------------------------------------------- |
| **Client ID**        | Consumer Key from the Connected App                                                         |
| **Client Secret**    | Consumer Secret from the Connected App                                                      |
| **Username**         | Salesforce username for the integration user                                                |
| **Password**         | Salesforce password appended with the user's security token                                 |
| **Access Token URL** | `https://login.salesforce.com/services/oauth2/token` (or `test.salesforce.com` for sandbox) |
| **Base URL**         | Your Salesforce instance URL, e.g. `https://your_instance.salesforce.com`                   |

## Set up Salesforce for API access

<Steps>
  <Step title="Enable API access on the integration user's profile">
    1. Log in to Salesforce with admin privileges.
    2. Go to **Setup → Users → Profiles**.
    3. Edit the profile for the user that will connect to PolyAI.
    4. Ensure **API Enabled** is checked.
  </Step>

  <Step title="Create a Connected App">
    1. Go to **Setup → App Manager**.
    2. Click **New Connected App**.
    3. Fill in the following:

    | Field                     | Value                                                                                                     |
    | ------------------------- | --------------------------------------------------------------------------------------------------------- |
    | **Connected App Name**    | `PolyAI Integration`                                                                                      |
    | **API Name**              | `PolyAIIntegration`                                                                                       |
    | **Contact Email**         | Your email                                                                                                |
    | **Enable OAuth Settings** | Checked                                                                                                   |
    | **Callback URL**          | Any HTTPS URL you control, e.g. `https://yourcompany.com/oauth/callback` — not actively used but required |
    | **Selected OAuth Scopes** | `Full Access (full)` and `Perform requests on your behalf at any time (refresh_token, offline_access)`    |

    4. Save the Connected App and copy the **Consumer Key** and **Consumer Secret** — these are your Client ID and Client Secret.
  </Step>

  <Step title="Share credentials with PolyAI">
    Send the values from the table above to your PolyAI representative. PolyAI uses them to generate the OAuth access token and stores them as encrypted secrets.
  </Step>
</Steps>

## Code example: create a Salesforce case

Once the integration is live, your agent can create cases through the Salesforce REST API. This is a simplified example of the underlying call.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import requests

def create_salesforce_case(base_url, access_token, case_data):
    """
    Create a case in Salesforce.

    :param base_url: Salesforce base URL (e.g., https://your_instance.salesforce.com)
    :param access_token: OAuth access token
    :param case_data: Dictionary containing case details
    """
    url = f"{base_url}/services/data/v55.0/sobjects/Case"
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    }

    response = requests.post(url, headers=headers, json=case_data)

    if response.status_code == 201:
        print("Case created successfully!", response.json())
    else:
        print("Failed to create case.", response.status_code, response.text)


if __name__ == "__main__":
    base_url = "https://your_instance.salesforce.com"
    access_token = "your_access_token"

    case_data = {
        "Subject": "Support Request",
        "Description": "Details about the issue.",
        "Origin": "Web",
        "Status": "New",
    }

    create_salesforce_case(base_url, access_token, case_data)
```

## Next steps

Once PolyAI has your credentials, the integration is configured on our side and you'll be contacted when it's ready. For custom functionality, contact your PolyAI account manager.

## Related pages

<CardGroup cols={2}>
  <Card title="Integrations overview" href="/integrations/introduction" icon="plug">
    Browse all available integrations.
  </Card>

  <Card title="Call handoffs" href="/voice-channel/handoffs" icon="phone-arrow-right">
    Configure agent handoff routing.
  </Card>
</CardGroup>

## Additional resources

* [Salesforce REST API documentation](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/)
* [OAuth 2.0 in Salesforce](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_web_server_flow.htm)
