---
schema_version: "1"
id: 337c59b245dae5b951e7fa5228d96bce0654da8e84277e8c3ed957dc7c281000
title: Get Started with the Service Connector API
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/service-connector-api/guides/service-connector-api-get-started.md
canonical_url: https://developer.salesforce.com/docs/service/service-connector-api/guide/service-connector-api-get-started.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: bed51a6a3ab2c1b699375da6ce3b0e905e5168ae8406f8ab5ca7baaf9a3fb822
products:
  - Service Connector API
  - Service Cloud Developer Content
---

# Get Started with the Service Connector API

The Connector API is the interface between your Contact Center as a Service (CCaaS) or telephony system and your Salesforce org. This API allows you to pass information to Salesforce and receive events back from Salesforce.

**important:** The Connector API is for partners who are implementing Bring Your Own Channel for CCaaS or Salesforce Voice with Partner Telephony.

## The Basics

To use the Connector API, you must call `initializeConnector()` (imported from Github) as the first step during the window load process. This function is part of the [Base Connector API](/docs/service/service-connector-api/references/connector-api-262/service-connector-api-base.html) and ensures that Salesforce can reliably establish two-way communication with the connector without any timing issues.

The [`initializeConnector()`](/docs/service/service-connector-api/references/connector-api-262/service-connector-base-initializeconnector.html) function takes your Connector API interface implementation as a parameter. Salesforce holds onto the `connector` implementation object during the entire session and this object must implement the required [Connector API Methods](/docs/service/service-connector-api/references/connector-api-262/service-connector-api-interface.html). If the connector requires loading any resources, we recommend that you do this outside of the connector object, so that they can be loaded asynchronously without delaying the call to `initializeConnector()`. After you call `initializeConnector()`, Salesforce calls the `init()` method on the Connector API interface with call center configuration information. This method returns a promise and can asynchronously load any resources before resolving the promise.

```html
<!-- Sample connector HTML -->
<html>
  <body>
    <div id="iframe" style="display: none;"></div>
  </body>
  <script type="module" src="connectordemo.js"></script>
</html>
```

```javascript
import { initializeConnector } from "scv-connector-base";
import { Sdk } from "./vendor-sdk";

const connector = new PartnerConnectorInterfaceImplementation();

// Calling the Connector API Base
window.addEventListener("load", () => {
  /**
   * initializeConnector should be called as early as possible
   * to allow Salesforce to reliably establish communication
   * with the connector
   */

  initializeConnector(connector);
});

// Connector API interface implementation
export class PartnerConnectorInterfaceImplementation {
  constructor(state) {
    this.sdk = new Sdk(state);
  }

  /**
   * Called by Salesforce to initialize the connector
   * @param {object} callCenterConfig - SFDC Contact Center Settings
   */
  init(callCenterConfig) {
    return new Promise((resolve, reject) => {
      this.sdk.performSSO(callCenterConfig).then((success) => {
        if (success) resolve(new InitResult({}));
        else reject("Failed to perform SSO");
      });
    });
  }
}
```

## Best Practices

Returning JavaScript promises in the connector greatly reduces the need to produce events or errors. Instead, the connector simply returns a resolved or rejected promise. A Connector API interface implementation must return a promise that resolves to a value of a specific type.

Here are some sample promises along with type checking.

```javascript
// Base connector
try {
    const result = await vendorConnector.setAgentStatus(agentStatus);

    // Validate result is of type GenericResult else throw error
    dispatchEvent(constants.EVENT_TYPE.SET_AGENT_STATUS_RESULT, { success });
} catch (e) {
    dispatchError(constants.ERROR_TYPE.CAN_NOT_SET_AGENT_STATUS, e);
}

// Connector
setAgentStatus(agentStatus) {
   return this.sdk.setAgentStatus(agentStatus).then((success) => {
        return new GenericResult({success});
   });
}

// Vendor
setAgentStaus(agentStatus) {
    return new Promise((resolve, reject) => {
        // Perform backend operations
        if (success) {
            resolve();
        } else {
            reject();
        }
    });
}
```

For telephony systems, if you’re using callbacks, you can convert them to promises as shown here:

```javascript
// Callback
function setAgentStatus(agentStatus) {
  getAgent().setAgentStatus(agentStatus, {
    success: (success) => {
      getTelephonyEventEmitter().emit(Constants.EVENT_TYPE.SET_AGENT_STATUS_RESULT, { success });
    },
    failure: (response) => {
      getTelephonyEventEmitter().emit(Constants.EVENT_TYPE.SET_AGENT_STATUS_RESULT, {
        success: false,
      });
    },
  });
}

// Promise
function setAgentStatus(agentStatus) {
  return new Promise((resolve, reject) => {
    getAgent().setAgentStatus(agentStatus, {
      success: (success) => {
        resolve({ success });
      },
      failure: (response) => {
        reject();
      },
    });
  });
}
```

**See Also**

- [Service Base Connector API](/docs/service/service-connector-api/references/connector-api-262/service-connector-api-base.html)
- [Service Connector API Methods](/docs/service/service-connector-api/references/connector-api-262/service-connector-api-interface.html)
