# Create a credential

> **POST** `https://api.us.nylas.com/v3/connectors/{provider}/creds`

Source: https://developer.nylas.com/docs/reference/api/connector-credentials/create_credential/

Manually create a credential record.

**Authentication:** NYLAS_API_KEY

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `provider` | string | Yes |  |

## Request body

Content-Type: application/json

- **Connector Override**
  - `name` (string) **(required)** - The name of the credential. Must be unique.
  - `credential_type` (string) **(required)** - The type of the credential. Set this value to `connector` if you have multiple provider auth applications for a single provider and need to create an override credential.  </br></br> For example, if you have two Google provider auth apps, the Google connector for each application can only connect to one of those Google auth apps by default. You can set up a connector override credential, however, then specify that credential ID in authentication requests so that the request goes through the Google connector, but goes to the non-default Google auth app.
  - `credential_data` (object) **(required)** - An object that contains special information that must be included in the credential.
This information is securely encrypted and stored, and isn't visible to users.

You must include data such as the `client_id` and `client_secret` for the provider
auth application.
- **Service Account**
  - `name` (string) **(required)** - The name of the credential. Must be unique.
  - `credential_type` (string) **(required)** - The type of the credential. For the App Permission flow (currently supported for [Google App Permission](/docs/v3/auth/bulk-auth-grants/#google-app-permission-via-nylas) only), the type must be `serviceaccount`.
  - `credential_data` (object) **(required)** - An object that specifies some special information required for the credential. This information is securely encoded and stored, and is _not_ visible to end users. </br></br> For the [Google App Permission flow](/docs/v3/auth/bulk-auth-grants/#google-app-permission-via-nylas), this field must contain the `private_key_id`, `private_key`, and `client_email`.
- **Admin Consent**
  - `name` (string) **(required)** - The name of the credential. Must be unique.
  - `credential_type` (string) **(required)** - The type of the credential. For the [Microsoft Admin Consent flow](/docs/v3/auth/bulk-auth-grants/#use-a-microsoft-bulk-authentication-grant), the type must be `adminconsent`.
  - `credential_data` (object) **(required)** - An object that specifies some special information required for the credential.
This information is securely encoded and stored, and isn't visible to users.

For the Microsoft Admin Consent 2.0 flow, this field must contain the `tenant`
(either yours or the user's). If you don't specify the Azure `client_id` and
`client_secret` Nylas uses the information from your Nylas application's
Microsoft connector.

## Responses

### 201 - The credential is created.

- `request_id` (string) - The request ID.
- `data` (object)
  - `id` (string) **(required)** - Credential ID
  - `name` (string) **(required)** - Unique name of this credential
  - `created_at` (integer) **(required)** - Date of creation of the credential
  - `updated_at` (integer) **(required)** - Initially same as `created_at`. Can differ if the credential has been updated.

### 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/<CONNECTOR>/creds' \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --data '{
    "name": "CONNECTOR",
    "credential_type": "connector",
    "credential_data": {
      "client_id": "<CLIENT_ID>",         // PROVIDER_CLIENT_ID or NYLAS_CLIENT_ID, depending on credential type.
      "client_secret": "<CLIENT_SECRET>"  // PROVIDER_CLIENT_SECRET or NYLAS_CLIENT_SECRET, depending on credential type.
    }
  }'
```

### Node.js SDK

```javascript
import Nylas, { CredentialType } from "nylas";

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

const credential = await nylas.connectors.credentials.create({
  provider: "google",
  requestBody: {
    name: "Google connector override",
    credentialType: CredentialType.CONNECTOR,
    credentialData: {
      client_id: "<CLIENT_ID>",
      client_secret: "<CLIENT_SECRET>",
    },
  },
});

console.log("Credential created:", credential);

```

### Python SDK

```python
from nylas import Client

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

credential = nylas.connectors.credentials.create(
    provider="google",
    request_body={
        "name": "Google connector override",
        "credential_type": "connector",
        "credential_data": {
            "client_id": "<CLIENT_ID>",
            "client_secret": "<CLIENT_SECRET>",
        },
    },
)

print("Created credential:", credential)

```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.AuthProvider;
import com.nylas.models.Credential;
import com.nylas.models.CreateCredentialRequest;
import com.nylas.models.CredentialData;
import com.nylas.models.NylasApiError;
import com.nylas.models.NylasSdkTimeoutError;
import com.nylas.models.Response;

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

    CredentialData.ConnectorOverride credentialData = new CredentialData.ConnectorOverride(
        "<CLIENT_ID>", "<CLIENT_SECRET>", null);

    CreateCredentialRequest requestBody = new CreateCredentialRequest.Connector(
        "Google connector override", credentialData);

    Response<Credential> credential = nylas.connectors().credentials()
        .create(AuthProvider.GOOGLE, requestBody);

    System.out.println("Credential created: " + credential.getData());
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.AuthProvider
import com.nylas.models.CreateCredentialRequest
import com.nylas.models.CredentialData

fun main() {
  val nylas = NylasClient.Builder("<NYLAS_API_KEY>").build()

  val credentialData = CredentialData.ConnectorOverride(
      clientId = "<CLIENT_ID>",
      clientSecret = "<CLIENT_SECRET>")

  val requestBody = CreateCredentialRequest.Connector(
      name = "Google connector override",
      credentialData = credentialData)

  val credential = nylas.connectors().credentials().create(AuthProvider.GOOGLE, requestBody)

  println("Credential created: ${credential.data}")
}

```
