# Delete a calendar

> **DELETE** `https://api.us.nylas.com/v3/grants/{grant_id}/calendars/{calendar_id}`

Source: https://developer.nylas.com/docs/reference/api/calendar/delete-calendars-id/

Deletes the specified calendar. You _cannot_ delete the primary calendar associated with an
account (`"is_primary": true`).

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `grant_id` | string | Yes | ID of the grant to access. Use `/me/` to refer to the grant associated with an access token. |
| `calendar_id` | string | Yes | ID of the calendar to access. You can use `primary` to refer to the primary calendar associated with a grant. Nylas recommends you URL-encode this field, or you might receive a [`404` error](/docs/api/errors/400-response/) if the ID contains special characters (for example, `#`). |

## Responses

### 200 - Delete Succeeded

- `request_id` (string) **(required)** - ID of the request.

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

```bash
curl --compressed --request DELETE \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/calendars/<CALENDAR_ID>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

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

async function deleteCalendar() {
  try {
    const calendar = await nylas.calendars.destroy({
      identifier: "<NYLAS_GRANT_ID>",
      calendarId: "<CALENDAR_ID>",
    });

    console.log("Calendar:", calendar);
  } catch (error) {
    console.error("Error to create calendar:", error);
  }
}

deleteCalendar();

```

### Python SDK

```python
from nylas import Client

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

grant_id = "<NYLAS_GRANT_ID>"
calendar_id = "<CALENDAR_ID>"

request = nylas.calendars.destroy(
  grant_id,
  calendar_id,
)

print(request)
```

### Ruby SDK

```ruby
# Load gems
require 'nylas'

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

# Create new calendar
calendar, = nylas.calendars.destroy(identifier: "<NYLAS_GRANT_ID>",
calendar_id: "<CALENDAR_ID>")

# Print calendar information
puts calendar
```

### Java SDK

```java
// Import packages
import com.nylas.NylasClient;
import com.nylas.models.*;

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

    // Delete the requested calendar
    try {
      nylas.calendars().destroy("<NYLAS_GRANT_ID>", "<CALENDAR_ID>", null);

      System.out.println("Deleted successfully");
    }
    catch(Exception e) {
      System.out.println("There was an error " + e);
    }
  }
}
```

### Kotlin SDK

```kotlin
// Import Nylas packages
import com.nylas.NylasClient
import com.nylas.models.*

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

  try {
    val calendar: DeleteResponse = nylas.calendars().destroy("<NYLAS_GRANT_ID>", "<CALENDAR_ID>")

    println("Deleted successfully")
  }catch (e: NylasApiError){
    println("There was an error $e")
  }
}
```
