> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CreateExternalDatabaseConnection

# Package: externalDatabases

# Namespace: ExternalDatabaseConnectionService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/external-databases/external-database-connection/create-external-database-connection.md

## Permission Scopes:
Manage External Database Connections: SCOPE.DC-DATA.EXTERNAL-DATABASE-CONNECTIONS-MANAGE

## Introduction

Creates a new external database connection.

Before you can establish a connection between a site and an external database, you must prepare an external database adaptor.

---

## REST API

### Schema

```
 Method: createExternalDatabaseConnection
 Description: Creates a new external database connection.  Before you can establish a connection between a site and an external database, you must prepare an external database adaptor.
 URL: https://www.wixapis.com/wix-data/v1/external-database-connections
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  externalDatabaseConnection, externalDatabaseConnection.name, connectionType
 Method parameters: 
   param name: connectionType | type: ConnectionType   | required: true 
      - enum:
           STANDALONE - External database connection based on the legacy [external database collection service plugin](https://dev.wix.com/docs/velo/api-reference/wix-data-v2/service-plugins-spis/external-database-collection-legacy/introduction.md).
           WIX_SERVICE_PLUGIN - External database connection based on the [external database service plugin](https://dev.wix.com/docs/rest/business-solutions/cms/service-plugins/external-database-service-plugin/introduction.md).
   param name: externalDatabaseConnection | type: ExternalDatabaseConnection | description: An external database connection defines a connection between an external database and a Wix site. | required: true 
        - name: name | type: string | description: Name of the external database connection.  An external database connection can connect to one or more external data collections or tables. These appear as `connectionName/dataCollectionId`. | required: true | validation: minLength 1, maxLength 255, immutable
        - name: endpoint | type: string | description: Base URL for accessing and managing data in the external database. For example: `https://example.com/my-external-database`. Required for STANDALONE connection type.  | validation: format WEB_URL
        - name: configuration | type: object | description: Settings specified to the external database connection as part of each request.  These settings can relate to authentication, tenancy, or provide any other information necessary for processing a request. Their content and structure depend on the specific requirements of the external database's API.  
 Return type: CreateExternalDatabaseConnectionResponse
  - name: externalDatabaseConnection | type: ExternalDatabaseConnection | description: Details of the created external database connection.  
     - name: name | type: string | description: Name of the external database connection.  An external database connection can connect to one or more external data collections or tables. These appear as `connectionName/dataCollectionId`.  | validation: minLength 1, maxLength 255, immutable
     - name: endpoint | type: string | description: Base URL for accessing and managing data in the external database. For example: `https://example.com/my-external-database`. Required for STANDALONE connection type.  | validation: format WEB_URL
     - name: configuration | type: object | description: Settings specified to the external database connection as part of each request.  These settings can relate to authentication, tenancy, or provide any other information necessary for processing a request. Their content and structure depend on the specific requirements of the external database's API.  
     - name: connectionStatus | type: ConnectionStatus | description: Status of the external database connection. Includes whether the connection was established successfully, and if not, the reason for the failure.  | read-only: true 
        - name: successful | type: boolean | description: Whether the connection was established successfully.  
        - name: causeOfFailure | type: CauseOfFailure | description: Whether and why the connection attempt failed.  
             - enum:
             -     NONE: No connection failure.
             -     COMMUNICATION_FAILURE: General communication failure.
             -     DESTINATION_HOST_UNREACHABLE: External database host is unreachable.
             -     UNAUTHORIZED: Unauthorized to access the external database.
             -     DESTINATION_ENDPOINT_NOT_DEFINED: `endpoint` is not set.
        - name: hasCollections | type: CollectionsFound | description: Whether the external database has collections.  | read-only: true 
             - enum:
             -     UNKNOWN: Attempt to connect to the external database failed, so status is unknown.
             -     YES: External database has collections.
             -     NO: External database does not have any collections.
     - name: publicKey | type: string | description: Public key used to validate requests to the external database.  | read-only: true | validation: maxLength 128
     - name: capabilities | type: Capabilities | description: Capabilities of the external database.  | read-only: true 
        - name: collectionModificationsSupported | type: boolean | description: Whether the external database supports creating new collections, updating the structure of existing collections, or deleting them.  
        - name: fieldTypes | type: array<FieldType> | description: Field types the external database supports. Applies only when `collectionModificationsSupported` is set to `true`.  | validation: maxItems 255
             - enum: TEXT, NUMBER, DATE, DATETIME, IMAGE, BOOLEAN, DOCUMENT, URL, RICH_TEXT, VIDEO, ANY, ARRAY_STRING, ARRAY_DOCUMENT, AUDIO, TIME, LANGUAGE, RICH_CONTENT, MEDIA_GALLERY, ADDRESS, PAGE_LINK, REFERENCE, MULTI_REFERENCE, OBJECT, ARRAY, LEGACY_TIME, LEGACY_BOOK, LEGACY_EXTERNAL_URL, LEGACY_BROKEN_REFERENCE, LEGACY_IMAGE, LEGACY_COLOR, LEGACY_EXTERNAL_VIDEO, EMAIL


```

### Examples

### Create an external database `WIX_SERVICE_PLUGIN` connection
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v1/external-database-connections' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
  "externalDatabaseConnection": {
    "name":"MyExternalDatabase",
    "endpoint":"https://example.com/my-external-database"
  },
  "connectionType": "WIX_SERVICE_PLUGIN"
}'
```

### Create an external database `STANDALONE` connection with additional configuration
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v1/external-database-connections' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
  "externalDatabaseConnection": {
    "name":"MyExternalDatabase",
    "endpoint":"https://example.com/my-external-database",
    "configuration":{
      "secretKey": "2b723306-4d74-42a2-8438-2ff40da3e6b6",
      "tenantId":"my-wix-site",
      "environment":"PRODUCTION",
      "collections":[
        "products",
        "categories"
      ]
    }
  },
  "connectionType": "STANDALONE"
}'
```

### Create an external database `STANDALONE` connection
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v1/external-database-connections' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
  "externalDatabaseConnection": {
    "name":"MyExternalDatabase",
    "endpoint":"https://example.com/my-external-database",
    "configuration":{
      "secretKey": "2b723306-4d74-42a2-8438-2ff40da3e6b6"
    }
  },
  "connectionType": "STANDALONE"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.externalDatabaseConnections.createExternalDatabaseConnection(externalDatabaseConnection, connectionType)
 Description: Creates a new external database connection.  Before you can establish a connection between a site and an external database, you must prepare an external database adaptor.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  externalDatabaseConnection, externalDatabaseConnection.name, connectionType
 Method parameters: 
   param name: externalDatabaseConnection | type: ExternalDatabaseConnection | description: An external database connection defines a connection between an external database and a Wix site. | required: true 
        - name: name | type: string | description: Name of the external database connection.  An external database connection can connect to one or more external data collections or tables. These appear as `connectionName/dataCollectionId`. | required: true | validation: minLength 1, maxLength 255, immutable
        - name: endpoint | type: string | description: Base URL for accessing and managing data in the external database. For example: `https://example.com/my-external-database`. Required for STANDALONE connection type.  | validation: format WEB_URL
        - name: configuration | type: object | description: Settings specified to the external database connection as part of each request.  These settings can relate to authentication, tenancy, or provide any other information necessary for processing a request. Their content and structure depend on the specific requirements of the external database's API.  
   param name: connectionType | type: ConnectionType   | required: true 
      - enum:
           STANDALONE - External database connection based on the legacy [external database collection service plugin](https://dev.wix.com/docs/velo/api-reference/wix-data-v2/service-plugins-spis/external-database-collection-legacy/introduction.md).
           WIX_SERVICE_PLUGIN - External database connection based on the [external database service plugin](https://dev.wix.com/docs/rest/business-solutions/cms/service-plugins/external-database-service-plugin/introduction.md).
 Return type: PROMISE<ExternalDatabaseConnection>
  - name: name | type: string | description: Name of the external database connection.  An external database connection can connect to one or more external data collections or tables. These appear as `connectionName/dataCollectionId`.  | validation: minLength 1, maxLength 255, immutable
  - name: endpoint | type: string | description: Base URL for accessing and managing data in the external database. For example: `https://example.com/my-external-database`. Required for STANDALONE connection type.  | validation: format WEB_URL
  - name: configuration | type: object | description: Settings specified to the external database connection as part of each request.  These settings can relate to authentication, tenancy, or provide any other information necessary for processing a request. Their content and structure depend on the specific requirements of the external database's API.  
  - name: connectionStatus | type: ConnectionStatus | description: Status of the external database connection. Includes whether the connection was established successfully, and if not, the reason for the failure.  | read-only: true 
     - name: successful | type: boolean | description: Whether the connection was established successfully.  
     - name: causeOfFailure | type: CauseOfFailure | description: Whether and why the connection attempt failed.  
         - enum:
         -     NONE: No connection failure.
         -     COMMUNICATION_FAILURE: General communication failure.
         -     DESTINATION_HOST_UNREACHABLE: External database host is unreachable.
         -     UNAUTHORIZED: Unauthorized to access the external database.
         -     DESTINATION_ENDPOINT_NOT_DEFINED: `endpoint` is not set.
     - name: hasCollections | type: CollectionsFound | description: Whether the external database has collections.  | read-only: true 
         - enum:
         -     UNKNOWN: Attempt to connect to the external database failed, so status is unknown.
         -     YES: External database has collections.
         -     NO: External database does not have any collections.
  - name: publicKey | type: string | description: Public key used to validate requests to the external database.  | read-only: true | validation: maxLength 128
  - name: capabilities | type: Capabilities | description: Capabilities of the external database.  | read-only: true 
     - name: collectionModificationsSupported | type: boolean | description: Whether the external database supports creating new collections, updating the structure of existing collections, or deleting them.  
     - name: fieldTypes | type: array<FieldType> | description: Field types the external database supports. Applies only when `collectionModificationsSupported` is set to `true`.  | validation: maxItems 255
         - enum: TEXT, NUMBER, DATE, DATETIME, IMAGE, BOOLEAN, DOCUMENT, URL, RICH_TEXT, VIDEO, ANY, ARRAY_STRING, ARRAY_DOCUMENT, AUDIO, TIME, LANGUAGE, RICH_CONTENT, MEDIA_GALLERY, ADDRESS, PAGE_LINK, REFERENCE, MULTI_REFERENCE, OBJECT, ARRAY, LEGACY_TIME, LEGACY_BOOK, LEGACY_EXTERNAL_URL, LEGACY_BROKEN_REFERENCE, LEGACY_IMAGE, LEGACY_COLOR, LEGACY_EXTERNAL_VIDEO, EMAIL


```

### Examples

### createExternalDatabaseConnection
```javascript
import { externalDatabaseConnections } from '@wix/data';

async function createExternalDatabaseConnection(externalDatabaseConnection,connectionType) {
  const response = await externalDatabaseConnections.createExternalDatabaseConnection(externalDatabaseConnection,connectionType);
};
```

### createExternalDatabaseConnection (with elevated permissions)
```javascript
import { externalDatabaseConnections } from '@wix/data';
import { auth } from '@wix/essentials';

async function myCreateExternalDatabaseConnectionMethod(externalDatabaseConnection,connectionType) {
  const elevatedCreateExternalDatabaseConnection = auth.elevate(externalDatabaseConnections.createExternalDatabaseConnection);
  const response = await elevatedCreateExternalDatabaseConnection(externalDatabaseConnection,connectionType);
}
```

### createExternalDatabaseConnection (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { externalDatabaseConnections } from '@wix/data';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { externalDatabaseConnections },
  // Include the auth strategy and host as relevant
});


async function createExternalDatabaseConnection(externalDatabaseConnection,connectionType) {
  const response = await myWixClient.externalDatabaseConnections.createExternalDatabaseConnection(externalDatabaseConnection,connectionType);
};
```

---