# Confirm a booking

> **PUT** `https://api.us.nylas.com/v3/scheduling/bookings/{booking_id}`

Source: https://developer.nylas.com/docs/reference/api/bookings/put-bookings-id/

Confirms or cancels the specified pending booking. Nylas also updates the associated event on the
provider.

Nylas validates the provided session ID and uses it to retrieve the related
[Configuration object](/docs/reference/api/configurations/). If you created a public
Configuration, you don't need to include the `Authorization` request header with a session ID, but
you do need to pass the Configuration object ID as a query parameter.

When you make a `PUT` request, Nylas replaces all data in the nested object with the information
included in your request. For more information, see
[Updating objects](/docs/reference/api/#updating-objects).

**Authentication:** SCHEDULER_SESSION_TOKEN

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `booking_id` | string | Yes | The ID of the booking object to access. |

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `configuration_id` | string | No | The ID of the Configuration object used for calculating availability. If you're using session authentication (`requires_session_auth: true`), the `configuration_id` isn't required. |
| `slug` | string | No | The Configuration object slug. You can use this with the `client_id` instead of using the `configuration_id`. If you're using session authentication (`requires_session_auth: true`) or using the `configuration_id`, `slug` isn't required. |
| `client_id` | string | No | The client ID that was used to create the Configuration object. Required only if you're using `slug`. |

## Request body

Content-Type: application/json

- `salt` (string) **(required)** - The salt extracted from the booking reference embedded in the organizer confirmation link, encoded as a URL-safe base64 string (without padding).
- `status` (string) **(required)** - The action to take on the pending booking.
- `cancellation_reason` (string) - The reason that the booking is being cancelled.

## Responses

### 200 - Booking confirmed or cancelled

- **Booking confirmed**
  - `request_id` (string) - The ID of the request.
  - `data` (object)
    - `booking_id` (string) - The unique ID of the booking.
    - `description` (string) - A brief description of the event.
    - `event_id` (string) - The event ID associated with the booking.
    - `organizer` (object) - The participant designated as the organizer of the event.
      - `email` (string) - The organizer's email address.
      - `name` (string) - The organizer's name.
    - `status` (string) - The status of the booking.
    - `title` (string) - The title of the event.
- **Booking cancelled**

### 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.

### 404 - Not Found

- `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 raw error from the provider, if available
    - `code` (string)
    - `message` (string)

### 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 (Public)

```bash
curl --compressed --request PUT \
  --url 'https://api.us.nylas.com/v3/scheduling/bookings/<BOOKING_ID>?configuration_id=<SCHEDULER_CONFIG_ID>' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
    "salt": -zgLLAuk_qtcsw,
    "status": "cancelled",
    "cancellation_reason": "I am no longer available at this time."
  }'
```

### cURL (Private)

```bash
curl --compressed --request PUT \
  --url 'https://api.us.nylas.com/v3/scheduling/bookings/<BOOKING_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <SCHEDULER_SESSION_ID>' \
  --header 'Content-Type: application/json' \ 
  --data '{
    "salt": -zgLLAuk_qtcsw,
    "status": "cancelled",
    "cancellation_reason": "I am no longer available at this time."
  }'
```

### Node.js SDK (Public)

```javascript
import Nylas from "nylas";

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

async function confirmBooking() {
  try {
    const booking = await nylas.scheduler.bookings.confirm({
      queryParams: {
        configurationId: "<SCHEDULER_CONFIG_ID>",
      },
      bookingId: "booking-id",
      requestBody: {
        salt: "-zgLLAuk_qtcsw",
        status: "cancelled",
        cancellationReason: "I am no longer available at this time.",
      },
    });
    console.log("Confirmed Booking", booking);
  } catch (error) {
    console.error("Error confirming booking", error);
  }
}

confirmBooking();

```

### Node.js SDK (Private)

```javascript
import Nylas from "nylas";

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

async function confirmBooking() {
  try {
    const booking = await nylas.scheduler.bookings.confirm({
      bookingId: "booking-id",
      requestBody: {
        salt: "-zgLLAuk_qtcsw",
        status: "cancelled",
        cancellationReason: "I am no longer available at this time.",
      },
    });
    console.log("Confirmed Booking", booking);
  } catch (error) {
    console.error("Error confirming booking", error);
  }
}

confirmBooking();

```

### Ruby SDK (Public)

```ruby
# Load gems
require 'nylas'

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

request_body = {
  "salt": "-zgLLAuk_qtcsw",
  "status": "cancelled",
  "cancellation_reason": "I am no longer available at this time."
}
booking, _request_ids = nylas.scheduler.bookings.confirm(booking_id: "<BOOKING_ID>", request_body: request_body, query_params: {"configuration_id": "<CONFIGURATION_ID>"})

puts booking
```

### Ruby SDK (Private)

```ruby
# Load gems
require 'nylas'

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

request_body = {
  "salt": "-zgLLAuk_qtcsw",
  "status": "cancelled",
  "cancellation_reason": "I am no longer available at this time."
}
booking, _request_ids = nylas.scheduler.bookings.confirm(booking_id: "<BOOKING_ID>", request_body: request_body)

puts booking
```

### Java SDK (Public)

```java
import com.nylas.NylasClient;
import com.nylas.models.Booking;
import com.nylas.models.ConfirmBookingQueryParams;
import com.nylas.models.ConfirmBookingRequest;
import com.nylas.models.ConfirmBookingStatus;
import com.nylas.models.NylasApiError;
import com.nylas.models.NylasSdkTimeoutError;
import com.nylas.models.Response;

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

    ConfirmBookingRequest requestBody = new ConfirmBookingRequest.Builder()
        .salt("-zgLLAuk_qtcsw")
        .status(ConfirmBookingStatus.CANCELLED)
        .cancellationReason("I am no longer available at this time.")
        .build();

    ConfirmBookingQueryParams queryParams = new ConfirmBookingQueryParams.Builder()
        .configurationId("<SCHEDULER_CONFIG_ID>")
        .build();

    Response<Booking> booking = nylas.scheduler().bookings().confirm(
        "<BOOKING_ID>", requestBody, queryParams);

    System.out.println("Confirmed booking: " + booking.getData());
  }
}

```

### Java SDK (Private)

```java
import com.nylas.NylasClient;
import com.nylas.models.Booking;
import com.nylas.models.ConfirmBookingRequest;
import com.nylas.models.ConfirmBookingStatus;
import com.nylas.models.NylasApiError;
import com.nylas.models.NylasSdkTimeoutError;
import com.nylas.models.Response;

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

    ConfirmBookingRequest requestBody = new ConfirmBookingRequest.Builder()
        .salt("-zgLLAuk_qtcsw")
        .status(ConfirmBookingStatus.CANCELLED)
        .cancellationReason("I am no longer available at this time.")
        .build();

    Response<Booking> booking = nylas.scheduler().bookings().confirm("<BOOKING_ID>", requestBody);

    System.out.println("Confirmed booking: " + booking.getData());
  }
}

```

### Kotlin SDK (Public)

```kotlin
import com.nylas.NylasClient
import com.nylas.models.ConfirmBookingQueryParams
import com.nylas.models.ConfirmBookingRequest
import com.nylas.models.ConfirmBookingStatus

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

  val requestBody = ConfirmBookingRequest.Builder()
      .salt("-zgLLAuk_qtcsw")
      .status(ConfirmBookingStatus.CANCELLED)
      .cancellationReason("I am no longer available at this time.")
      .build()

  val queryParams = ConfirmBookingQueryParams.Builder()
      .configurationId("<SCHEDULER_CONFIG_ID>")
      .build()

  val booking = nylas.scheduler().bookings().confirm("<BOOKING_ID>", requestBody, queryParams)

  println("Confirmed booking: ${booking.data}")
}

```

### Kotlin SDK (Private)

```kotlin
import com.nylas.NylasClient
import com.nylas.models.ConfirmBookingRequest
import com.nylas.models.ConfirmBookingStatus

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

  val requestBody = ConfirmBookingRequest.Builder()
      .salt("-zgLLAuk_qtcsw")
      .status(ConfirmBookingStatus.CANCELLED)
      .cancellationReason("I am no longer available at this time.")
      .build()

  val booking = nylas.scheduler().bookings().confirm("<BOOKING_ID>", requestBody)

  println("Confirmed booking: ${booking.data}")
}

```
