# Create a session

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

Source: https://developer.nylas.com/docs/reference/api/sessions/post-sessions/

Creates a new short-lived session that you can pass to the Scheduling Component to enforce user
authentication. Your request must include the ID of an existing Configuration object.

**Authentication:** NYLAS_API_KEY

## Request body

Create a new scheduling session

Content-Type: application/json

- `configuration_id` (string) - The ID of the Scheduler Configuration object for the session. If you're using `slug`, `configuration_id` is not required.
- `slug` (string) - The slug of the Scheduler Configuration object for the session. You can use `slug` instead of `configuration_id`.
- `time_to_live` (number) - The time to live for the session in minutes. The maximum value is `30`.

## Responses

### 200 - Create a new scheduling session

- `request_id` (string) - The request ID.
- `data` (object)
  - `session_id` (string) - The ID of the session

### 400 - Bad Request

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 401 - Unauthorized

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 429 - Rate Limit

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

### 504 - Provider Failure

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

## Code samples

### cURL

```bash
curl --compressed --request POST \
  --url "https://api.us.nylas.com/v3/scheduling/sessions" \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "configuration_id": "<SCHEDULER_CONFIGURATION_ID>",
    "time_to_live": 10
  }'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

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

async function createSession() {
  try {
    const session = await nylas.scheduler.sessions.create({
      requestBody: {
        configurationId: "<CONFIGURATION_ID>",
        timeToLive: 30,
      },
    });

    console.log("Session:", session);
  } catch (error) {
    console.error("Error creating session:", error);
  }
}

createSession();

```

### Python SDK

```python
from nylas import Client

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

session = nylas.scheduler.sessions.create(
    request_body={
        "configuration_id": "<SCHEDULER_CONFIG_ID>",
        "time_to_live": 30,
    },
)

print("Created session:", session)

```

### Ruby SDK

```ruby
# Load gems
require 'nylas'

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

request_body = {
  "configuration_id": "<SCHEDULER_CONFIG_ID>",
  "time_to_live": 30
}

session, _request_ids = nylas.scheduler.sessions.create(request_body: request_body)

puts session
```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.CreateSessionRequest;
import com.nylas.models.NylasApiError;
import com.nylas.models.NylasSdkTimeoutError;
import com.nylas.models.Response;
import com.nylas.models.Session;

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

    CreateSessionRequest requestBody = new CreateSessionRequest.Builder()
        .configurationId("<CONFIGURATION_ID>")
        .timeToLive(30)
        .build();

    Response<Session> session = nylas.scheduler().sessions().create(requestBody);

    System.out.println("Session: " + session.getData());
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.CreateSessionRequest

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

  val requestBody = CreateSessionRequest.Builder()
      .configurationId("<CONFIGURATION_ID>")
      .timeToLive(30)
      .build()

  val session = nylas.scheduler().sessions().create(requestBody)

  println("Session: ${session.data}")
}

```
