> ## 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 **Configure > Integrations** in Agent Studio under **CRM**.</Note>

## Prerequisites

Ensure you have the following before integrating:

1. A **Salesforce Account**: Administrator access to a Salesforce instance.
2. **PolyAI Access**: Access credentials for the PolyAI Portal.

## Set up Salesforce for API access

Follow these steps to enable API access in Salesforce:

1. **Enable API Access**:
   * Log in to Salesforce with admin privileges.
   * Go to **Setup > Users > Profiles**.
   * Edit the profile for the user account that will connect to PolyAI.
   * Ensure the checkbox for **API Enabled** is selected.
2. **Create a Connected App**:
   * Go to **Setup > App Manager**.
   * Click **New Connected App**.
   * Fill in the following details:
     * **Connected App Name**: `PolyAI Integration`.
     * **API Name**: `PolyAIIntegration`.
     * **Contact Email**: Enter your email.
     * **Enable OAuth Settings**: Check this box.
     * **Callback URL**: Enter a valid callback URL for your organization. This can be any HTTPS URL you control (e.g., `https://yourcompany.com/oauth/callback`). For PolyAI integrations, this URL is not actively used but is required by Salesforce OAuth configuration.
     * **Selected OAuth Scopes**: Add `Full Access (full)` and `Perform requests on your behalf at any time (refresh_token, offline_access)`.
   * Save the connected app and note the **Consumer Key** and **Consumer Secret**.
3. **Provide PolyAI with the Required Information**:
   * **Client ID**: The Consumer Key of your Connected App.
   * **Client Secret**: The Consumer Secret of your Connected App.
   * **Username**: The Salesforce username for the integration.
   * **Password**: The Salesforce password for the user, appended with the security token.
   * **Access Token URL**: Typically `https://login.salesforce.com/services/oauth2/token` (for production) or `https://test.salesforce.com/services/oauth2/token` (for sandbox).
   * **Base URL**: The root URL of your Salesforce instance (e.g., `https://your_instance.salesforce.com`).

PolyAI will use these details to generate the necessary `access_token`. Credentials will be passed in the Authorization header as specified in the OAuth spec.

## Code example

The following is a simplified Python example that demonstrates how to create a case in Salesforce using their REST API.

```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)

# Example usage
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 you provide PolyAI with the credentials above, the integration will be configured and you will 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="/call-handoff/introduction" 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 Documentation](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_web_server_flow.htm)
