createExternalDatabaseConnection( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Creates a new external database connection.

The externalDatabaseConnection parameter must include a name, endpoint, and configuration details for the external database. If any of these are missing, the external database connection isn't created.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage External Database Connections
Learn more about app permissions.
Method Declaration
Copy
function createExternalDatabaseConnection(
  externalDatabaseConnection: ExternalDatabaseConnection,
  options: CreateExternalDatabaseConnectionOptions,
): Promise<ExternalDatabaseConnection>;
Method Parameters
externalDatabaseConnectionExternalDatabaseConnectionRequired

External database connection details.


optionsCreateExternalDatabaseConnectionOptions

Options for creating an external database connection.

Returns
Return Type:Promise<ExternalDatabaseConnection>
JavaScript
import { externalDatabaseConnections } from "wix-data.v2"; import { elevate } from "wix-auth"; const elevatedCreateExternalDbConnection = elevate( externalDatabaseConnections.createExternalDatabaseConnection, ); /* Sample externalDatabaseConnection object: * * { * capabilities: { * collectionModificationsSupported: false, * fieldTypes: [] * }, * configuration: { * secretKey: '74dbd6d6-ec5b-4668-8229-c77379bc6431' * }, * endpoint: 'https://example.com/my-external-database', * name: 'connectionOne' * } */ export async function myCreateExternalDbConnectionFunction( newExternalDatabaseConnection, ) { try { const createExternalDbConnectionResponse = await elevatedCreateExternalDbConnection(newExternalDatabaseConnection); const dbConnectionStatus = createExternalDbConnectionResponse.connectionStatus; const dbCapabilities = createExternalDbConnectionResponse.capabilities; console.log( "Successfully created an external database connection. Full response:", createExternalDbConnectionResponse, ); return createExternalDbConnectionResponse; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * * { * "capabilities": { * "collectionModificationsSupported": false, * "fieldTypes": [] * } * "configuration": { * "secretKey": "74dbd6d6-ec5b-4668-8229-c77379bc6431" * }, * "connectionStatus": { * "causeOfFailure": "NONE", * "hasCollections": "YES" * "successful": true, * }, * "endpoint": "https://example.com/my-external-database", * "name": "connectionOne", * "protocolVersion": "V2", * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?