# Create a connector

> **POST** `https://api.us.nylas.com/v3/connectors`

Source: https://developer.nylas.com/docs/reference/api/connectors-integrations/create_connector/

Create a connector in your Nylas application.

Connectors are how your Nylas application stores information it needs to connect to external
services. Creating a connector is the first step in setting up authentication for your project.
See [Supported providers](/docs/provider-guides/#supported-providers) for more information.

**Authentication:** NYLAS_API_KEY

## Request body

Content-Type: application/json

- **Google**
  - `provider` (string) **(required)** - The provider type. For Google providers, set to `google`.
  - `settings` (object) - GCP provider auth app credentials and settings.
    - `client_id` (string) **(required)** - The GCP app's client ID.
    - `client_secret` (string) **(required)** - The GCP app's client secret.
    - `topic_name` (string) - Google Pub/Sub topic name. Required if using Email webhooks.
  - `scope` (array) - Set the default scopes for each connector. These scopes are overridden by scopes set on the specific grant.
- **Microsoft**
  - `provider` (string) **(required)** - The provider type. For Microsoft providers, set to `microsoft`.
  - `settings` (object) - Your Azure provider auth app credentials and settings, as stored in Entra ID.
    - `client_id` (string) **(required)** - The Azure auth app's client ID.
    - `client_secret` (string) **(required)** - The Azure auth app's client secret.
    - `tenant` (string) - Microsoft tenant ID.
  - `scope` (array) - Set the default scopes for each connector. Scopes set on individual grants override these scopes.
For Microsoft Graph connectors, the Nylas API accepts both the full URI version of a scope name (for example, `https://graph.microsoft.com/Calendars.Read`), as well as the short form (for example, `Calendars.Read`).
- **Zoom**
  - `provider` (string) **(required)** - The provider type. For Zoom providers, set to `zoom`.
  - `settings` (object) - Zoom provider credentials and settings. You can copy them from your [Zoom App](https://developers.zoom.us/docs/zoom-apps/) in [Zoom Developer Platform](https://developers.zoom.us/docs/). The Zoom Nylas connector does not support default scopes, so do not include them in the connector request.

However, you must configure the required [granular scopes](https://developers.zoom.us/docs/integrations/oauth-scopes-granular/) directly on your Zoom OAuth app. To use Zoom conferencing with Nylas events, your Zoom app needs: `meeting:write:meeting` (create), `meeting:update:meeting` (update), and `meeting:delete:meeting` (delete).
    - `client_id` (string) **(required)** - The Zoom app's client ID.
    - `client_secret` (string) **(required)** - The Zoom app's client secret.
- **iCloud**
  - `provider` (string) **(required)** - The provider type, in this case `icloud`. See
[Authenticating iCloud accounts](/docs/provider-guides/icloud/) for more
information.
- **IMAP**
  - `provider` (string) **(required)** - The provider type, in this case `imap`. See
[Using IMAP accounts and data](/docs/provider-guides/imap/) for more information.
- **EWS**
  - `provider` (string) **(required)** - The provider type (in this case, `ews`). See
[Authenticating Exchange on-premises accounts](/docs/provider-guides/exchange-on-prem/)
for more information.
  - `scopes` (string) - Scopes settings tell Nylas to request specific data objects from the provider.
- **Virtual calendars**
  - `provider` (string) **(required)** - The provider type. For virtual calendars, set to `virtual-calendar`.
- **Yahoo**
  - `provider` (string) **(required)** - The provider type (in this case, `yahoo`). See
[Authenticating Yahoo accounts](/docs/provider-guides/yahoo/) for more information.
  - `settings` (object) - Yahoo provider credentials.
    - `client_id` (string) **(required)** - The Yahoo app's client ID.
    - `client_secret` (string) **(required)** - The Yahoo app's client secret.
  - `scope` (array) - Set the default scopes for each connector. These scopes are overridden by scopes set on the specific grant.
- **Nylas (Agent Account)**
  - `provider` (string) **(required)** - The provider type (in this case, `nylas`).

## Responses

### 201 - Connector Created

- `request_id` (string) - ID of the request.
- `data` (object)
  - `name` (string) **(required)** - The name of the connector.
  - `provider` (string) **(required)** - Provider type
  - `settings` (object) - Optional settings from provider
  - `scope` (array) - (Not used for Zoom connectors.) Optional default scopes for the connector. For Zoom, configure scopes directly on your Zoom OAuth app. See [Zoom granular scopes](https://developers.zoom.us/docs/integrations/oauth-scopes-granular/).
  - `active_credential_id` (string) - The ID of the "default" credential record of this Connector. This credential will be used as a default for communication with the provider.

### 400 - Bad Request

- `request_id` (string) **(required)** - ID of the request
- `error` (object) **(required)** - Error object
  - `type` (string) - Type of error
  - `message` (string) - Informative error message
  - `provider_error` (object) - (OPTIONAL) informative error message from provider's side

### 401 - Not Authenticated

- `request_id` (string) **(required)** - ID of the request
- `error` (object) **(required)** - Error object
  - `type` (string) - Type of error
  - `message` (string) - Informative error message
  - `provider_error` (object) - (OPTIONAL) informative error message from provider's side

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.us.nylas.com/v3/connectors' \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --data '{
    "provider": "google",
    "settings": {
      "client_id": "<NYLAS_CLIENT_ID>",
      "client_secret": "<NYLAS_CLIENT_SECRET>",
      "topic_name": "<TOPIC_NAME>"
    },
    "scope": [
      "https://www.googleapis.com/auth/userinfo.email",
      "https://www.googleapis.com/auth/userinfo.profile"
    ]
  }'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function createConnector() {
  try {
    const connector = await nylas.connectors.create({
      requestBody: {
        name: "google",
        provider: "google",
        settings: {
          clientId: "<GCP_CLIENT_ID>",
          clientSecret: "<GCP_CLIENT_SECRET>",
        },
        scope: [
          "openid",
          "https://www.googleapis.com/auth/userinfo.email",
          "https://www.googleapis.com/auth/gmail.modify",
          "https://www.googleapis.com/auth/calendar",
          "https://www.googleapis.com/auth/contacts",
        ],
      },
    });

    console.log("Connector created:", connector);
  } catch (error) {
    console.error("Error creating connector:", error);
  }
}

createConnector();

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>",
)

connector = nylas.connectors.create(
    request_body={
        "provider": "google",
        "settings": {
            "client_id": "<GCP_CLIENT_ID>",
            "client_secret": "<GCP_CLIENT_SECRET>",
        },
        "scopes": [
            "openid",
            "https://www.googleapis.com/auth/userinfo.email",
            "https://www.googleapis.com/auth/gmail.modify",
            "https://www.googleapis.com/auth/calendar",
            "https://www.googleapis.com/auth/contacts",
        ],
    }
)

```

### Ruby SDK

```ruby
require 'nylas'

nylas = Nylas::Client.new(
    api_key: "<NYLAS_API_KEY>"
)

request_body = {
  provider: "google",
  settings: {
    clientId: "<GCP_CLIENT_ID>",
    clientSecret: "<GCP_CLIENT_SECRET>",
  },
  scope: [
    'openid',
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/gmail.modify',
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/contacts',
  ]
}

nylas.connectors.create(request_body: request_body)
```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;
import java.util.ArrayList;
import java.util.List;

public class connector {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
    NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();

    List<String> scope = new ArrayList<>();
    scope.add("openid");
    scope.add("https://www.googleapis.com/auth/userinfo.email");
    scope.add("https://www.googleapis.com/auth/gmail.modify");
    scope.add("https://www.googleapis.com/auth/calendar");
    scope.add("https://www.googleapis.com/auth/contacts");

    GoogleCreateConnectorSettings settings = new GoogleCreateConnectorSettings(
        "<GCP_CLIENT_ID>",
        "<GCP_CLIENT_SECRET>",
        ""
    );

    CreateConnectorRequest request = new CreateConnectorRequest.Google(settings, scope);

    nylas.connectors().create(request);
  }
}  
```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.CreateConnectorRequest
import com.nylas.models.GoogleCreateConnectorSettings

fun main(args: Array<String>) {
  val nylas: NylasClient = NylasClient(
      apiKey = "<NYLAS_API_KEY>"
  )

  var scope = listOf(
      "openid",
      "https://www.googleapis.com/auth/userinfo.email",
      "https://www.googleapis.com/auth/gmail.modify",
      "https://www.googleapis.com/auth/calendar",
      "https://www.googleapis.com/auth/contacts"
  )

  val settings : GoogleCreateConnectorSettings = GoogleCreateConnectorSettings(
      "<GCP_CLIENT_ID>",
      "<GCP_CLIENT_SECRET>",
      ""
  )

  val request : CreateConnectorRequest = CreateConnectorRequest.Google(settings, scope)
  
  nylas.connectors().create(request)
}
```
