# Data Connector

The [Salesforce REST API](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest.htm) is a data service that allows object data and meta data in Salesforce to be securely accessed by custom applications.

The WireBootstrap for Salesforce Data Connector is a [WireBootstrap data connector](https://docs.wirebootstrap.com/wirebootstrap/connecting-to-data/data-connectors) that can talk to Salesforce using the Salesforce REST API. &#x20;

Using the data connector, Salesforce objects can be queried from WireBootstrap applications.  The data connector also provides access to Salesforce meta data such as lists of objects and their fields using [WireBootstrap's data discovery](https://docs.wirebootstrap.com/wirebootstrap/connecting-to-data/discovery) features.

## Data Source

To use the data connector, create a [WireBootstrap data source](https://docs.wirebootstrap.com/wirebootstrap/connecting-to-data/data-sources) using the connector's service provider key in the initialization.  The service provider key for the WireBootstrap for Salesforce Data Connector is `sf`.

```javascript
const source = new wire.data.DataSource("sf", {
    ...
});
```

### Authentication

For security, the Salesforce REST API requires an access token.  For details on creating a Salesforce access token, visit [Access Tokens](https://docs.wirebootstrap.com/salesforce/access-tokens).

Below is a sample access token object returned from a call to Salesforce for a token.

```javascript
const response = {
    instance_url: "https://domain-dev-my.salesforce.com",
    access_token: "eyJ0e...Agjmg"
    token_type: "Bearer"
}
```

To set up the security for data source calls, use the `Headers` property during the data source initialization.  Set `Authorization` property using the token response object returned from Salesforce.

```javascript

const source = new wire.data.DataSource("sf", {
    Headers: { Authorization: response.token_type + " " + reponse.access_token },
    ...      
});
```

### Service Root

Use the `ServiceRoot` configuration property on the data source to specify the end point for the Salesforce REST API.    This will be in the `instance_url` property on the token response object.

```javascript
const source = new wire.data.DataSource("sf", {
    ServiceRoot: response.instance_url,
    ...
});
```

## CORS

CORS must be configured in Salesforce to allow the WireBootstrap for Salesforce Data Connector to access data returned from calls to Salesforce from a web browser. &#x20;

For details visit, [Configure Salesforce CORS Allow List](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/extend_code_cors.htm).
