Skip to main content

Create Data Source

Use this API to create a new database connection configuration in NineData. The request supports common connection fields and type-specific options such as MongoDB deployment settings and SSL configuration.

Request URL: /openapi/v1/datasource/create

Request Method: POST

Request Parameters

ParameterTypeRequiredDescriptionExample
datasourceTypeStringYesData source type. Supported values: MYSQL, MARIADB, POSTGRESQL, SQLSERVER, DAMENG, KINGBASE, KINGBASE_ORACLE, MILVUS, MONGODB. Values are case-insensitive. Uppercase is recommended.MONGODB
nameStringYesSpecify the name of the data source.Production Environment MongoDB
usernameStringNoAccount for accessing the data source.root
passwordStringNoPassword for accessing the data source. Required for MongoDB data sources.Root
hostStringYesConnection address of the data source. For MongoDB standalone mode, pass an IP address or domain name. For a replica set or sharded cluster, pass a comma-separated string in the host1:port1,host2:port2 format.192.168.1.1
portIntegerNoPort number of the data source. Required for MongoDB standalone mode. Do not pass this parameter for a MongoDB replica set or sharded cluster because port information is included in host.27017
envIdStringNoBind this data source to a specific environment. Call the List Environments API to get envId.env-product
regionIdStringNoRegion where the data source belongs. Call the List Regions API to get regionId.aliyun-cn-hangzhou
networkTypeStringNoSpecify the connection method of the data source. Currently, only public network access is supported, with the value being Public.Public
extraConfigObjectNoData-source-specific configuration. Put type-specific parameters in this object.{"authDB":"admin"}
sslConfigObjectNoSSL configuration. Currently supported only for MySQL, SQLServer, and PostgreSQL. Do not pass this parameter for MongoDB.{"securityConfig":"PREFERRED"}

MongoDB-Specific extraConfig Parameters

ParameterTypeRequiredDefaultDescriptionExample
mongoDBDeploymentTypeStringNostandaloneMongoDB deployment type. Values: standalone, replicaSet, shardedCluster.replicaSet
authDBStringYes-Authentication database.admin
readPreferenceStringNo-Read preference. Values: primary, primaryPreferred, secondary, secondaryPreferred, nearest.secondaryPreferred
replicaSetStringNo-Replica set name. Pass this parameter for MongoDB replica set mode.rs0
clusterObjectNo-Explicitly specify topology information for a MongoDB replica set or sharded cluster. If this object is passed, all fields listed below are required except available.{"clusterId":"cluster-1","nodeList":[...]}
cluster.clusterIdStringYes-Cluster ID.cluster-1
cluster.nodeListArrayYes-Cluster node list.-
cluster.nodeList[].nodeIdStringYes-Node ID.node-1
cluster.nodeList[].nodeHostStringYes-Host name.mongo-0
cluster.nodeList[].nodePortIntegerYes-Port.27017
cluster.nodeList[].connectHostStringYes-Connection address.192.168.1.10
cluster.nodeList[].connectPortStringYes-Connection port.27017
cluster.nodeList[].clusterIdStringYes-ID of the cluster that the node belongs to.cluster-1
cluster.nodeList[].availableStringNoTRUEWhether the node is available.TRUE

SSL Configuration Parameters

Only MySQL, SQLServer, and PostgreSQL data sources support sslConfig. Supported fields vary by data source type.

ParameterTypeRequiredApplicable Data SourcesDescriptionExample
securityConfigStringNoMySQL, PostgreSQLSSL security mode. MySQL values: REQUIRED, PREFERRED; PostgreSQL values: Prefer, Require, Verify-CA, Verify-Full.PREFERRED
sslCipherStringNoMySQLSSL cipher suite.TLS_AES_256_GCM_SHA384
sslCAStringNoMySQL, SQLServer, PostgreSQLCA certificate content.-----BEGIN CERTIFICATE-----
sslCAFileNameStringNoMySQL, SQLServer, PostgreSQLCA certificate file name.ca.pem
sslClientCertStringNoMySQL, PostgreSQLClient certificate content.-----BEGIN CERTIFICATE-----
sslClientCertFileNameStringNoMySQL, PostgreSQLClient certificate file name.client-cert.pem
sslClientKeyStringNoMySQL, PostgreSQLClient private key content.-----BEGIN PRIVATE KEY-----
sslClientKeyFileNameStringNoMySQL, PostgreSQLClient private key file name.client-key.pem
sslIndentifyBooleanNoMySQLWhether to verify the server identity. Use the field name sslIndentify as required by the API.false
hostNameInCertificateStringNoSQLServerHost name in the server certificate.db.example.com
trustServerCertificateBooleanNoSQLServerWhether to trust the server certificate.false

Request Example

MongoDB standalone:

{
"name": "Production Environment MongoDB",
"username": "root",
"password": "Root",
"host": "192.168.1.10",
"port": 27017,
"datasourceType": "MongoDB",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"extraConfig": {
"mongoDBDeploymentType": "standalone",
"authDB": "admin"
}
}

MySQL SSL:

{
"name": "Production Environment MySQL",
"username": "root",
"password": "Root",
"host": "192.168.1.10",
"port": 3306,
"datasourceType": "MYSQL",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"sslConfig": {
"securityConfig": "PREFERRED",
"sslIndentify": false
}
}

MongoDB replica set:

{
"name": "Production Environment MongoDB Replica Set",
"username": "root",
"password": "Root",
"host": "192.168.1.10:27017,192.168.1.11:27017",
"datasourceType": "MongoDB",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"extraConfig": {
"mongoDBDeploymentType": "replicaSet",
"authDB": "admin",
"readPreference": "secondaryPreferred",
"replicaSet": "rs0"
}
}

Return Parameters

ParameterTypeDescriptionExample
successBoolWhether the API call was successful. Return values: true, false.true
requestIdStringRequest ID.Mi6y0FCN-BHEEaHAnCFFp9DFdAAk0OUZ
dataArrayDetails of the created data source, including data source ID (datasourceId) information.{
"datasourceId": "ds-d92r4i7z1a90"
}

Successful Invocation Example

{
"success": true,
"requestId": "Uf0f0KQB-BHEEjCWnCGHo9FSdCBi1GPC",
"data": {
"datasourceId": "ds-d92r4i7z1a90"
}
}

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.