# Hosted OAuth - Revoke OAuth token

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

Source: https://developer.nylas.com/docs/reference/api/authentication-apis/revoke_oauth2_token_and_grant/

Revokes the specified OAuth access token. When you revoke the token, Nylas _doesn't_ revoke the
grant or the associated provider token. This means that a user can re-authenticate to get a new
access token for the existing grant, so their `grant_id` doesn't change.

If you revoke a Nylas access token, Nylas also revokes all child tokens and the parent
`refresh_token` attached to the access token.

**Authentication:** ACCESS_TOKEN, NYLAS_API_KEY

## Parameters

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `token` | string | Yes | The token to revoke |

## Responses

### 200 - The token was revoked successfully.



### 400 - The token could not be revoked, possibly because it was invalid or already expired.

- `error` (string) - Error type constant.
- `error_description` (string) - Human readable error description.
- `error_uri` (string) - A url to the related documentation and troubleshooting regarding this error.
- `error_code` (string) - Error code used for referencing the docs, logs and data stream.

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.us.nylas.com/v3/connect/revoke?token=<TOKEN>' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
```

### Node.js SDK

```javascript
import Nylas from "nylas";

// Configure the Nylas SDK with your API key and server URL
const NylasConfig = {
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
};

const nylas = new Nylas(NylasConfig);

const revokeToken = async () => {
  try {
    const token = "<TOKEN>";
    const response = await nylas.auth.revoke(token);

    console.log("Token Revoked:", response);
  } catch (error) {
    console.error("Error removing connector:", error);
  }
};

revokeToken();

```

### Python SDK

```python
import sys
from nylas import Client

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

request = nylas.auth.revoke(
  "<TOKEN>",
)

print(request)
```

### Ruby SDK

```ruby
# frozen_string_literal: true

require 'nylas'

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

begin
  nylas.auth.revoke("<NYLAS_AUTH_TOKEN>")
  puts "The token was successfully revoked"
rescue Nylas::NylasApiError => e
  puts "The token could not be revoked: #{e.message}"
end

```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.TokenParams;

public class Main {
    public static void main(String[] args) {
        NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();
        TokenParams token = new TokenParams("<NYLAS_ACCESS_TOKEN>");

        try {
            boolean tokenStatus = nylas.auth().revoke(token);
            if (tokenStatus) {
                System.out.println("The token was successfully removed");
            } else {
                System.out.println("The token cannot be removed");
            }
        } catch (Exception e) {
            System.out.println("Invalid token cannot be removed");
        }
    }
}

```

### Kotlin SDK

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

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

    val token = TokenParams("<NYLAS_ACCESS_TOKEN>")

    try {
        val tokenStatus = nylas.auth().revoke(token)
        if (tokenStatus) {
            println("The token was successfully removed")
        } else {
            println("The token cannot be removed")
        }
    } catch (e: Exception) {
        print("Invalid token cannot be removed")
    }
}

```
