# Deregister a Connection

**Required Immuta permission**: `APPLICATION_ADMIN`

To deregister a connection from Immuta, do the following:

1. [Generate a script to clean up any Immuta-managed resources from your Snowflake or Databricks Unity Catalog environment](#step-1-generate-the-cleanup-script). For AWS Lake Formation connections, skip to step 2.
2. [Delete the connection in Immuta](#step-2-delete-the-connection-in-immuta).
3. [Run the script in Databricks Unity Catalog or Snowflake to clean up any Immuta-managed resources from your environment](#step-3-run-the-cleanup-script-in-your-data-platform).

## Step 1: Generate the cleanup script

<mark style="color:green;">`POST`</mark> `/integrations/{id}/scripts/delete`

Creates a script to remove Immuta-managed resources from your data platform.

```
curl -X 'POST' \
    'https://www.organization.immuta.com/integrations/1/scripts/delete' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: 846e9e43c86a4ct1be14290d95127d13f'
```

#### Path parameters

| Attribute        | Description                                                                                                                                                                                                                                       | Required |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| **id** `integer` | The integration ID. Use the [<mark style="color:blue;">`GET /integrations`</mark>](/SaaS/developer-guides/api-intro/integrations-api/reference-guides/integrations-api.md#get-integrations) endpoint to list all your integrations and their IDs. | **Yes**  |

#### Response <a href="#response-8" id="response-8"></a>

The response returns the script that you will run in your Databricks Unity Catalog or Snowflake environment. Copy it for later.

## Step 2: Delete the connection in Immuta

<mark style="color:green;">`DELETE`</mark> `/data/object/{connectionKey}`

Delete the given connection and all its child objects.

```
curl -X 'DELETE' \
    'https://<your-immuta-url>/data/object/yourConnectionKey' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: <your-bearer-token>' \
```

#### Path parameters

| Attribute                  | Description                                                                                                           | Required |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------- |
| **connectionKey** `string` | The key to uniquely identify the connection. This is the same as the display name of the connection in the Immuta UI. | **Yes**  |

#### Response schema

| Attribute                  | Description                                                       |
| -------------------------- | ----------------------------------------------------------------- |
| **connectionKey** `string` | The key to uniquely identify the connection.                      |
| **childCount** `integer`   | The number of child objects of the data object that were deleted. |

#### Example response

```
{
  "objectPath": ['yourConnectionKey'],
  "childCount": 5
}
```

## Step 3: Run the cleanup script in your data platform

{% hint style="warning" %}
**Cleaning up your Snowflake environment**\
Until you manually run the cleanup script in your Snowflake environment, Immuta-managed [roles](/SaaS/configuration/integrations/snowflake/reference-guides/table-grants-overview.md#table-grants-role) and Immuta policies will still exist in Snowflake.
{% endhint %}

Using the copied generated cleanup script from earlier, run it in your Snowflake or Databricks Unity Catalog environment as a privileged user.

The script will remove any objects that were initially created during the [Register a connection](/SaaS/developer-guides/api-intro/connections-api/how-to-guides/register-a-connection.md) process.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.immuta.com/SaaS/developer-guides/api-intro/connections-api/how-to-guides/deregister-a-connection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
