Skip to main content

Create Data Source

Use this API to create a new data source connection configuration in NineData.

Request URL: /openapi/v1/datasource/create

Request Method: POST

Request Parameters

ParameterTypeRequiredDescriptionExample
datasourceTypeStringYesData source type. Pass one of the enum values in the table below. Availability depends on the data source types enabled in the target NineData environment.mysql
nameStringYesSpecify the name of the data source.Example MongoDB
usernameStringConditionalDatabase username. The exact requirement depends on the data source type and authentication mode. See Username and Password Requirements.<username>
passwordStringConditionalDatabase password. It has the same required conditions as username. See Username and Password Requirements.<password>
hostStringYesPass an IP address or domain for a standalone data source; for a replica set or sharded cluster, pass host1:port1,host2:port2.<DB_HOST>
portIntegerNoRequired in standalone mode. Omit it for replica sets or sharded clusters and include port information in host.27017
envIdStringNoEnvironment. Call List Environments to get it.<envId>
regionIdStringNoRegion where the data source belongs. Call the List Regions API to get regionId.<regionId>
networkTypeStringNoConnection method. Defaults to public when omitted. Values: public, gateway, private, and ssh.public
masterNameStringNoPrimary node name for a data source with a primary node.master-1
hostAndPortsStringNoComma-separated host:port pairs for multiple nodes, for example, Redis Sentinel or Cluster nodes.host1:port1,host2:port2
instanceIdStringNoRequired when cloudInstanceType=instance.<instanceId>
instanceTypeStringNoCloud instance type. Values: ECS, EC2, RDS, Express, Polardb, PolardbX, DRDS, TDSQL, GaussDB, DDS, Aurora, Redis, Kafka, Elasticsearch, ADB, Doris, SCS, MongoDB, DocumentDB, Redshift, clickhouse, GaiaDB, GaiaDBX, OceanBase, VectorDB, VastBase, GoldenDB, CloudSQL, AlloyDB, and GoogleCloud.RDS
cloudInstanceTypeStringNoCloud instance access mode. Values: instance and url.instance
vendorRegionIdStringNoCloud vendor region ID.cn-hangzhou
serverVersionStringNoDatabase server version.8.0
gatewayIdStringNoPass it when networkType=gateway.<gatewayId>
tunnelIdStringNoUsually pass it when networkType=private; the current interface does not enforce it.<tunnelId>
accessIdStringNoCloud provider access credential ID used for cloud API calls.<accessId>
envStringNoEnvironment identifier selected by the request.<environment>
sshConfigObjectNoRequired when networkType=ssh to provide SSH connection settings. See SSHConfig structure.{}
extraConfigObjectNoData-source-specific configuration. Put type-specific parameters in this object. See the details below.{"authDB":"admin"}

Required-parameter rules

The Required column describes the general request requirement. The actual request must also combine fields according to datasourceType, networkType, and the access mode. Send only the fields required by the selected scenario:

ScenarioRequired fields or rule
Every create requestdatasourceType and name. datasourceType must also be enabled in the target NineData environment.
Connect in standalone modehost and port are required.
Connect a replica set or sharded clusterhost is required and must contain the nodes and ports in the form host1:port1,host2:port2; omit port.
Omit networkTypeThe request is processed as public.
networkType=gatewayPass gatewayId.
networkType=privateUsually pass tunnelId; the current interface does not enforce it, and omission may be processed as a direct connection.
networkType=sshsshConfig is required.
cloudInstanceType=instanceinstanceId is required.
Use a cloud provider APIPass accessId for the target cloud environment. For DataHub, the credential's AccessKey and AccessKeySecret are used as the username and password.
Specify an environment or regionPass envId or regionId. If envId is omitted, env-dev is used by default; validation fails if that environment does not exist.

Do not replace a field that is not required in the selected scenario with an empty string. Put database credentials, SSH credentials, and cloud provider credentials in their corresponding fields; do not mix them.

The supported datasourceType enum values are:

Data sourcedatasourceType
MySQLmysql
SQL Serversqlserver
Oracleoracle
PostgreSQLpostgresql
ClickHouseclickhouse
Elasticsearchelasticsearch
OpenSearchopensearch
Trinotrino
ShardingJDBCsharding_jdbc
ShardingProxysharding_proxy
Kafkakafka
Redisredis
MongoDBmongodb
Dorisdoris
SelectDBselectdb
StarRocksstarrocks
OceanBase Oracleoceanbaseoracle
OceanBase MySQLoceanbasemysql
Amazon Redshiftredshift
Greenplumgreenplum
YMatrixymatrix
DB2db2
SingleStoresinglestore
Klustronklustron
Kingbasekingbase
Kingbase Oraclekingbaseoracle
Damengdameng
DWSdws
Hivehive
ADB PostgreSQLadbpostgresql
openGaussopengauss
GaussDBgaussdb
PanWeiDBpanweidb
GBasegbase
GBase 8agbase8a
TiDBtidb
Sybasesybase
GreatSQLgreatsql
TDSQL MySQLtdsqlmysql
TDSQL Oracletdsqloracle
DataHubdatahub
ElastiCacheelasticache
VectorDBvectordb
VastBasevastbase
Lindorm MySQLlindormmysql
GoldenDBgoldendb
PegaDBpega
Milvusmilvus
Chromachroma
Qdrantqdrant
Pineconepinecone
Weaviateweaviate
MariaDBmariadb
PolarDB Oraclepolardboracle
PolarDB-Xpolardbx
PolarDB-X Centralizedpolardbxcentralized
DRDSdrds
SQL Databasesqldatabase
Memorystorememorystore
HANAhana
YashanDByashandb
YashanDB MySQLyashandbmysql
MaxComputemaxcompute
HaishanDBhaishandb

Available data source types vary by version and deployment environment. The API returns INVALID_PARAMETER when the value is not enabled in the target environment.

Data Source Types and extraConfig Details

datasourceType determines the type-specific fields that can be used in extraConfig. The table lists the mappings confirmed in the reference appendix. A dash () means that the type has no type-specific extraConfig fields. Availability depends on the data source types enabled in the target NineData environment.

Data source type (datasourceType)Type-specific extraConfig fields
MySQL (mysql)mysqlConnectionType
Oracle (oracle)serviceName, sid, role
PostgreSQL (postgresql)authDB, clientTimezone
Kafka (kafka)kafkaAuthorization
Redis (redis)redisDeploymentType; masterName is a top-level field for Sentinel mode, not an extraConfig field
MongoDB (mongodb)mongoDBDeploymentType, authDB, readPreference, serverSelectionTimeoutMS, cluster
Doris (doris), SelectDB (selectdb), StarRocks (starrocks)dorisUserBeHostPorts
OceanBase Oracle (oceanbaseoracle)serviceName, sid, sysTenantUsername, sysTenantPassword
OceanBase MySQL (oceanbasemysql)mysqlConnectionType, sysTenantUsername, sysTenantPassword
Amazon Redshift (redshift)authDB
Greenplum (greenplum)authDB
DB2 (db2)dbName
GaussDB (gaussdb)gaussDBInstanceType, gaussDBBigVersion
GBase (gbase)serverName
GBase 8a (gbase8a)connectionType, host
MariaDB (mariadb)mysqlConnectionType
PolarDB Oracle (polardboracle)clientTimezone
PolarDB-X (polardbx)mysqlConnectionType, clientTimezone
PolarDB-X Centralized (polardbxcentralized)mysqlConnectionType
DRDS (drds)mysqlConnectionType
Memorystore (memorystore)redisDeploymentType
HANA (hana)databaseName
YashanDB (yashandb)serviceName, sid
Hive (hive)hadoopAuthConfig
Other currently supported types; pass top-level fields and follow validation in the target environment

Note: In the current environment, the read-only GET /openapi/v1/datasource/list response also returns version- or type-specific fields for some types, such as useCompression, beHostsEnable, and dorisMapping; SSL responses may also contain tlsAllowInvalidCertificates, tlsAllowInvalidHostnames, and tlsInsecure. These are response extensions and are not included in the generic create-request field list. Before sending them to the create API, verify them against the target environment's interface definition.

extraConfig Object Structure

extraConfig is a JSON object. Its keys are case-sensitive. When creating a data source, pass the type-specific fields for the selected datasourceType. Do not put top-level fields, such as the Redis masterName, inside this object by mistake.

ParameterTypeRequiredDescription
clientTimezoneStringNoClient time zone, such as +08:00 or -05:00.
mysqlConnectionTypeStringNoMySQL connection type. See the table below for values and host formats.
mongoDBDeploymentTypeStringNoMongoDB deployment type. Values: standalone, replicaSet, shardedCluster. The default is standalone.
authDBStringConditionalMongoDB authentication database; default database for PostgreSQL, Greenplum, and Amazon Redshift. Required when creating MongoDB data sources.
readPreferenceStringNoMongoDB read preference. Values: primary, primaryPreferred, secondary, secondaryPreferred, nearest, default.
serverSelectionTimeoutMSIntegerNoMongoDB server-selection timeout. The default is 10000.
redisDeploymentTypeStringNoRedis deployment type. Values: single, sentinel, cluster.
kafkaAuthorizationStringNoKafka authentication method. Values: PLAINTEXT, SASL/PLAIN, SASL/SCRAM-SHA-256, SASL/SCRAM-SHA-512.
serviceNameStringConditionalOracle service name. Use it or sid, but not both.
sidStringConditionalOracle SID. Use it or serviceName, but not both.
roleStringNoOracle privilege role. Values: SYSDBA, SYSOPER, default.
dbNameStringYesDB2 database name.
databaseNameStringNoDatabase name for data source types that require it in extraConfig.
gaussDBInstanceTypeStringNoGaussDB instance type. Values: centralized, distributed.
gaussDBBigVersionStringNoGaussDB major version. Values: GaussDB 8.x, GaussDB 3.x.
serverNameStringNoGBase server name. The default is gbaseserver.
clientCharsetStringNoClient character set.
connectionTypeStringNoGBase 8a connection type. Values: standalone, multi; the legacy value single is also supported. Required for primary/standby mode.
hostStringNoStandby node address for GBase 8a when connectionType=multi; separate multiple addresses with semicolons (;).
sysTenantUsernameStringConditionalOceanBase system-tenant username.
sysTenantPasswordStringConditionalOceanBase system-tenant password.
dorisUserBeHostPortsArrayNoBE node list for Doris, SelectDB, or StarRocks. Each element has the form {"host":"<BE_HOST>","port":"8040"}.
hadoopAuthConfigObjectConditionalHive authentication settings. When authMethod=KERBEROS, pass Kerberos authentication information in this object; top-level username and password can be omitted.
clusterObjectNoMongoDB cluster topology. It contains clusterId and a required nodeList; see below.

MySQL connection types:

mysqlConnectionTypehost formatDescription
single<DB_HOST> plus portDirect single-node connection (default).
failover<HOST_1>:<PORT_1>,<HOST_2>:<PORT_2>MySQL failover connection that switches to an available node.
replication<HOST_1>:<PORT_1>,<HOST_2>:<PORT_2>MySQL read/write splitting connection.

Redis and Kafka rules:

  • When redisDeploymentType=sentinel, the top-level masterName is required and host contains the Sentinel node list.
  • When redisDeploymentType=cluster, host contains the cluster node list and port can be omitted.
  • When kafkaAuthorization is SASL/PLAIN, SASL/SCRAM-SHA-256, or SASL/SCRAM-SHA-512, the top-level username and password are the Kafka authentication credentials. You can omit them when the value is PLAINTEXT or is not passed.

extraConfig.cluster Structure

ParameterTypeRequiredDescription
clusterIdStringNoCluster ID.
nodeListArrayYesCluster node list.

Each nodeList element has the following structure:

ParameterTypeRequiredDescription
nodeIdStringNoNode ID.
nodeHostStringYesNode address.
nodePortIntegerYesNode port.
connectHostStringNoConnectable address. Defaults to nodeHost.
connectPortIntegerNoConnectable port. Defaults to nodePort.
usernameStringNoNode username.

SSHConfig Structure

When networkType=ssh, pass the SSH tunnel settings in the top-level sshConfig object. sshPassword is required when sshAuthType is password; sshPrivateKey is required when sshAuthType is privateKey.

ParameterTypeRequiredDescription
sshHostStringYesSSH host.
sshPortIntegerNoSSH port. The default is 22.
sshUsernameStringYesSSH username.
sshAuthTypeStringNoSSH authentication method. Values: password, privateKey.
sshPasswordStringConditionalRequired when sshAuthType=password. SSH password.
sshPrivateKeyStringConditionalRequired when sshAuthType=privateKey. SSH private-key content.
sshPrivateKeyFileNameStringNoSSH private-key file name.
sshPassphraseStringNoSSH private-key passphrase. Leave it empty when the key has no passphrase.
jumpServerListArrayNoJump-server list. Each element has the same structure as this object.

SSH private-key authentication example:

{
"networkType": "ssh",
"sshConfig": {
"sshHost": "<SSH_HOST>",
"sshPort": 22,
"sshUsername": "<SSH_USERNAME>",
"sshAuthType": "privateKey",
"sshPrivateKey": "<SSH_PRIVATE_KEY>",
"sshPrivateKeyFileName": "id_rsa",
"sshPassphrase": "<SSH_PASSPHRASE>"
}
}

Username and Password Requirements

username and password are database or data source credentials. SSH credentials belong in sshConfig. A create request must include them according to the data source type and authentication method:

Scenariousername/password requirement
MySQL, MariaDB, TiDB, OceanBase MySQL, TDSQL MySQL, PolarDB-X, PolarDB-X Centralized, DRDS, SingleStore, GBase 8a, GreatSQL, GoldenDB, Lindorm MySQL, PostgreSQL, Greenplum, Amazon Redshift, SQL Server, Oracle, OceanBase Oracle, Dameng, YashanDB, DB2, HANA, GaussDB, DWS, GBase, Sybase, Doris, SelectDB, StarRocks, Kingbase, Kingbase OracleRequired when creating the data source.
MongoDBRequired when creating the data source. Set the authentication database with extraConfig.authDB.
Redis, ElastiCache, Memorystore, PegaDBRequired when account authentication is used; omit them when no authentication is configured.
KafkaRequired when kafkaAuthorization is SASL/PLAIN, SASL/SCRAM-SHA-256, or SASL/SCRAM-SHA-512; omit them when it is PLAINTEXT or not passed.
HiveWhen hadoopAuthConfig.authMethod=KERBEROS, top-level username and password can be omitted; for other authentication methods, follow the target authentication configuration.
Elasticsearch, ClickHouse, Trino, ShardingJDBC, and similar typesFollow the target data source authentication method; omit them when authentication is disabled.

If the credentials do not satisfy the authentication requirements for the selected data source type, the API may return a parameter-validation error. Do not replace unused credentials with empty strings, and do not put an SSH password in the top-level password field.

MongoDB Standalone extraConfig Parameters

When you create a MongoDB standalone data source, pass the following fields in extraConfig.

ParameterTypeRequiredDescriptionExample
mongoDBDeploymentTypeStringNoMongoDB deployment type. Pass standalone for standalone mode.standalone
authDBStringYesAuthentication database.admin

Request Example

The examples below use a gateway to access non-public databases. If the target database is reachable directly from the NineData public network, change networkType to public and remove gatewayId. The network type must match the actual address and network configuration.

MongoDB standalone:

{
"name": "Example MongoDB",
"username": "<username>",
"password": "<password>",
"host": "<DB_HOST>",
"port": 27017,
"datasourceType": "mongodb",
"regionId": "<regionId>",
"envId": "<envId>",
"networkType": "gateway",
"gatewayId": "<gatewayId>",
"extraConfig": {
"mongoDBDeploymentType": "standalone",
"authDB": "admin"
}
}

MySQL:

{
"name": "Example MySQL",
"username": "<username>",
"password": "<password>",
"host": "<DB_HOST>",
"port": 3306,
"datasourceType": "mysql",
"regionId": "<regionId>",
"envId": "<envId>",
"networkType": "gateway",
"gatewayId": "<gatewayId>"
}

PostgreSQL:

{
"name": "Example PostgreSQL",
"username": "<username>",
"password": "<password>",
"host": "<DB_HOST>",
"port": 5432,
"datasourceType": "postgresql",
"regionId": "<regionId>",
"envId": "<envId>",
"networkType": "gateway",
"gatewayId": "<gatewayId>",
"extraConfig": {
"authDB": "<DATABASE_NAME>",
"clientTimezone": "+08:00"
}
}

Oracle (SERVICE_NAME):

{
"name": "Example Oracle",
"username": "<username>",
"password": "<password>",
"host": "<DB_HOST>",
"port": 1521,
"datasourceType": "oracle",
"regionId": "<regionId>",
"envId": "<envId>",
"networkType": "gateway",
"gatewayId": "<gatewayId>",
"extraConfig": {
"serviceName": "<SERVICE_NAME>"
}
}

Return Parameters

ParameterTypeDescriptionExample
successBoolWhether the API call was successful. Return values: true, false.true
requestIdStringRequest ID.<requestId>
dataObjectDetails of the created data source, including data source ID (datasourceId) information.{"datasourceId":"<datasourceId>"}

Successful Invocation Example

{
"success": true,
"requestId": "<requestId>",
"data": {
"datasourceId": "<datasourceId>"
}
}

Result

A successful response returns the created data source ID in data.datasourceId. Use this ID when you query, update, delete, or grant permissions for the data source.