> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Connect to your Databricks app for OAuth or API Key

Databricks supports two authentication methods. Choose the one that best fits your use case:

* **API Key Authentication** - Best for internal integrations using a Personal Access Token
* **OAuth 2.0 Authentication** - Best for end-user authorization using PKCE (no client secret required)

## API Key Authentication

To successfully connect with the **Databricks** integration using API Key, a Linked Account or an end-user will need to provide the following:

1. API Key (Personal Access Token)
2. Base URL

<Info>
  To understand how a Linked Account can get the above mentioned credentials, refer below.
</Info>

### Getting Credentials of Databricks

To acquire the required credentials and connect a Linked Account, please follow the steps mentioned below:

1. Log in to your Databricks workspace at your workspace URL (e.g., `https://<workspace-id>.azuredatabricks.net`).
2. Click on your profile icon in the top right corner and select `Settings`.

<img height="200" src="https://mintcdn.com/cobalt-55/dSAvB__VyvkR_YcE/images/Databricks/databricks_navigation.png?fit=max&auto=format&n=dSAvB__VyvkR_YcE&q=85&s=25c43abc632cf46f6e380e7091e1463b" alt="Navigation for Personal Access Token" data-path="images/Databricks/databricks_navigation.png" />

3. Navigate to `Developer` in the left menu > Click on the `Manage` button next to **Access tokens** as shown above.
4. Click `Generate new token`.

<img height="200" src="https://mintcdn.com/cobalt-55/dSAvB__VyvkR_YcE/images/Databricks/databricks_credentials.png?fit=max&auto=format&n=dSAvB__VyvkR_YcE&q=85&s=49acc5f1c592f6bd079551c43d2695b0" alt="Getting Personal Access Token" data-path="images/Databricks/databricks_credentials.png" />

5. Provide a **Comment** (e.g., "Refold Integration") and set a **Lifetime** for the token. Select any particular scopes as should be accessible by the Refold Databricks connector. Click `Generate`.
6. Copy the token displayed on the screen. This is your **API Key**.

<img height="200" src="https://mintcdn.com/cobalt-55/dSAvB__VyvkR_YcE/images/Databricks/databricks_credentials_2.png?fit=max&auto=format&n=dSAvB__VyvkR_YcE&q=85&s=ba65c9bf9375952d7f54110a5d559d79" alt="Obtain the API Key" data-path="images/Databricks/databricks_credentials_2.png" />

<Warning>
  The token will only be shown once. Copy and store it immediately. If lost, you will need to revoke and generate a new token.
</Warning>

7. Your **Base URL** is the workspace URL you used to log in (e.g., `https://<workspace-id>.azuredatabricks.net`).

The Linked Account or end-user now have all the credentials required to connect with Databricks using API Key authentication.

***

## OAuth 2.0 Authentication

To setup your Databricks app in Refold for OAuth, you will need the following credentials from your Databricks account console:

* Client ID
* Workspace URL

<Info>
  Databricks OAuth uses PKCE (Proof Key for Code Exchange), so no client secret is required. You will need to register a new app connection in the Databricks account console.
</Info>

### Creating an OAuth App Connection in Databricks

To create a Databricks OAuth app connection and acquire the above mentioned credentials, please follow the steps mentioned below:

1. Log in to your Databricks account console at [https://accounts.cloud.databricks.com](https://accounts.cloud.databricks.com).

<img height="200" src="https://mintcdn.com/cobalt-55/qGo-0h2ROb2bW8eS/images/Databricks/DB_landingpage.png?fit=max&auto=format&n=qGo-0h2ROb2bW8eS&q=85&s=be57781a43768ee6f84e49e934376f14" alt="Databricks Account Console Landing Page" data-path="images/Databricks/DB_landingpage.png" />

2. Click on **Settings** in the left sidebar.
3. Navigate to the **App connections** tab.

<img height="200" src="https://mintcdn.com/cobalt-55/qGo-0h2ROb2bW8eS/images/Databricks/db_appconnections.png?fit=max&auto=format&n=qGo-0h2ROb2bW8eS&q=85&s=949a6ba54f6b0f0e8507aed813a06bd0" alt="App Connections in Databricks Settings" data-path="images/Databricks/db_appconnections.png" />

4. Click on **Add connection** in the top right corner.
5. Fill in the connection details:
   * **Application Name**: Give your app a descriptive name (e.g., "Refold-databricks-app").
   * **Redirect URLs**: Go to your [`Apps catalog`](https://app.refold.ai/apps) in **Refold** > Search for `Databricks` > `Settings` > `Use your credentials` > `Callback Url` > Copy it and paste it here.
   * **Access scopes**: Select the required scopes (e.g., `SQL` or `All APIs`).
   * **Client secret**: Leave the **Generate a client secret** checkbox **unchecked** — Databricks OAuth with PKCE does not require a client secret.

<img height="200" src="https://mintcdn.com/cobalt-55/qGo-0h2ROb2bW8eS/images/Databricks/db_addConnection.png?fit=max&auto=format&n=qGo-0h2ROb2bW8eS&q=85&s=dfdc8ee6a3e1ea930b0bde45a3738e86" alt="Add Connection Form in Databricks" data-path="images/Databricks/db_addConnection.png" />

6. Click **Add**. A **Connection created** popup will appear displaying your **Client ID**. Copy it and store it securely.

<img height="200" src="https://mintcdn.com/cobalt-55/qGo-0h2ROb2bW8eS/images/Databricks/db_clientId.png?fit=max&auto=format&n=qGo-0h2ROb2bW8eS&q=85&s=194893584d8a31dad4ef667ac5726d51" alt="Client ID from Databricks App Connection" data-path="images/Databricks/db_clientId.png" />

7. Navigate to **Workspaces** in the left sidebar, click on your workspace, and copy the **Workspace URL** shown in the configuration (e.g., `https://dbc-<id>.cloud.databricks.com`).

<img height="200" src="https://mintcdn.com/cobalt-55/qGo-0h2ROb2bW8eS/images/Databricks/db_copyworkspaceurl.png?fit=max&auto=format&n=qGo-0h2ROb2bW8eS&q=85&s=7e97ec287c64922a9da993c15cbd8f5b" alt="Copy Workspace URL from Databricks" data-path="images/Databricks/db_copyworkspaceurl.png" />

#### Configuring OAuth credentials in Refold

App settings page lets you configure the authentication settings for an `OAuth2` based application. For your customers to provide you authorization to access their data, they would first need to install your application. This page lets you set up your application credentials.

Provide the acquired **Client ID** and **Workspace URL** under Settings of the Databricks app in Refold and save it.

#### Configuring Scopes

Refold lets you configure what permissions to ask from your users while they install your application. The scopes can be added or removed from the App settings page, under `Permissions & Scopes` section.

For some applications Refold sets **mandatory scopes** which cannot be removed. Additional scopes can be selected from the drop down. Refold also has the provision to add any custom scopes supported by the respective platform.

<Warning>
  If you are facing scopes missing or invalid scope error, make sure the scopes selected in Refold match those configured in your Databricks app connection. And, ensure you are not passing any custom scope not supported by the platform.
</Warning>

***

#### Actions and triggers

Once the above setup is completed, you can create orchestrations of your use-cases using Databricks actions and triggers. Following are the set of Databricks actions and triggers supported by Refold.

<Tabs>
  <Tab title="Actions">
    <AccordionGroup>
      <Accordion title="Catalogs">
        1. **Query Catalogs** - Gets an array of catalogs in the metastore in Databricks.
        2. **Create Catalog** - Creates a new catalog instance in the parent metastore in Databricks.
        3. **Retrieve Catalog** - Gets the specified catalog in a metastore in Databricks.
        4. **Update Catalog** - Updates the catalog that matches the supplied name in Databricks.
        5. **Delete Catalog** - Deletes the catalog that matches the supplied name in Databricks.
      </Accordion>

      <Accordion title="Clusters">
        6. **Create Cluster** - Create a new cluster in Databricks.
        7. **List Clusters** - List all pinned and active clusters in Databricks.
        8. **Get Cluster Info** - Get information about a specific cluster in Databricks.
        9. **Query Clusters** - Return information about all pinned, active, and recently terminated clusters in Databricks.
        10. **Start Cluster** - Start a terminated cluster in Databricks.
        11. **Restart Cluster** - Restart a running cluster in Databricks.
        12. **Terminate Cluster** - Terminate a cluster in Databricks.
        13. **Delete Cluster** - Permanently terminates a cluster and removes it asynchronously in Databricks.
      </Accordion>

      <Accordion title="Groups">
        14. **List Groups** - Get all group details in Databricks.
        15. **Create Group** - Create a new group in Databricks.
        16. **Update Group** - Update group details in Databricks.
        17. **Delete Group** - Delete a group in Databricks.
      </Accordion>

      <Accordion title="Jobs">
        18. **Create Job** - Create a new job in Databricks.
        19. **Query Jobs** - Retrieves a list of jobs in Databricks.
        20. **Show Job** - Retrieves the details for a single job in Databricks.
        21. **Update Job** - Add, update, or remove specific settings of an existing job in Databricks.
        22. **Delete Job** - Delete a job in Databricks.
        23. **Run Job** - Run a job and return the run ID of the triggered run in Databricks.
        24. **Get Job Run** - Retrieves the metadata of a run in Databricks.
        25. **Cancel Run** - Cancels a job run or a task run asynchronously in Databricks.
      </Accordion>

      <Accordion title="Schemas">
        26. **Query Schemas** - Gets an array of schemas for a catalog in the metastore in Databricks.
        27. **Create Schema** - Creates a new schema for a catalog in the metastore in Databricks.
        28. **Retrieve Schema** - Gets the specified schema within the metastore in Databricks.
        29. **Update Schema** - Updates a schema for a catalog in Databricks.
        30. **Delete Schema** - Deletes the specified schema from the parent catalog in Databricks.
      </Accordion>

      <Accordion title="SQL Statements">
        31. **Execute Statement** - Execute a SQL statement and optionally await its results in Databricks.
        32. **Retrieve Statement** - Poll for the status and results of a SQL statement execution in Databricks.
        33. **Retrieve Statement Result Chunk** - Fetch a paginated chunk of results from a completed SQL statement in Databricks.
        34. **Cancel Statement Execution** - Request that an executing SQL statement be canceled in Databricks.
      </Accordion>

      <Accordion title="Tables">
        35. **Query Tables** - Gets an array of all tables for a catalog and schema in the metastore in Databricks.
        36. **Retrieve Table** - Gets a table from the metastore for a specific catalog and schema in Databricks.
        37. **Check Table Exists** - Checks if a table exists in the metastore for a specific catalog and schema in Databricks.
        38. **Query Table Summaries** - Gets an array of summaries for tables under a schema and catalog in Databricks.
        39. **Delete Table** - Deletes a table from the specified parent catalog and schema in Databricks.
      </Accordion>

      <Accordion title="Users">
        40. **List Users** - Get details for all users in Databricks.
        41. **Create User** - Create a new user in Databricks.
        42. **Get User** - Get user details by ID in Databricks.
        43. **Update User** - Update an existing user in Databricks.
        44. **Delete User** - Delete a user in Databricks.
      </Accordion>

      <Accordion title="Volumes">
        45. **Query Volumes** - Gets an array of volumes for a catalog and schema in the metastore in Databricks.
        46. **Create Volume** - Creates a new volume in Databricks.
        47. **Retrieve Volume** - Gets a volume from the metastore for a specific catalog and schema in Databricks.
        48. **Update Volume** - Updates the specified volume in Databricks.
        49. **Delete Volume** - Deletes a volume from the specified parent catalog and schema in Databricks.
      </Accordion>

      <Accordion title="Warehouses">
        50. **Query Warehouses** - Lists all SQL warehouses that a user has manager permissions on in Databricks.
        51. **Create Warehouse** - Creates a new SQL warehouse in Databricks.
        52. **Retrieve Warehouse** - Gets the information for a single SQL warehouse in Databricks.
        53. **Update Warehouse** - Updates the configuration for a SQL warehouse in Databricks.
        54. **Start Warehouse** - Starts a SQL warehouse in Databricks.
        55. **Stop Warehouse** - Stops a SQL warehouse in Databricks.
        56. **Delete Warehouse** - Deletes a SQL warehouse in Databricks.
      </Accordion>

      <Accordion title="Workspace">
        57. **Import Workspace** - Import a workspace object (notebook or file) or the contents of an entire directory in Databricks.
        58. **Export Workspace** - Export a workspace object or the contents of an entire directory in Databricks.
        59. **List Workspace** - List the contents of a directory in Databricks.
        60. **Retrieve Object Status** - Gets the status of an object or directory in Databricks.
        61. **Delete Workspace** - Deletes an object or a directory in Databricks.
        62. **Query Directories** - Lists the contents of a directory, or the object if it is not a directory in Databricks.
        63. **Create Directory** - Creates the specified directory and any necessary parent directories in Databricks.
      </Accordion>

      <Accordion title="Others">
        64. **HTTP Request** - Make HTTP API calls to any Databricks documented REST APIs.
        65. **Incremental Sync** - Check for new data in the endpoint.
      </Accordion>
    </AccordionGroup>
  </Tab>

  <Tab title="Triggers">
    There are no triggers in this application.
  </Tab>
</Tabs>
