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. Use a DatasourceType enabled in the target NineData environment. Values are case-insensitive; preserve the spelling shown by the product.MONGODB
nameStringYesSpecify the name of the data source.Production Environment MongoDB
usernameStringConditionalDatabase account. Whether it is required depends on the data source type.root
passwordStringConditionalDatabase password. It has the same required conditions as username.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
envIdStringNoEnvironment. Call List Environments to get it. Default: env-dev.env-product
regionIdStringNoRegion where the data source belongs. Call the List Regions API to get regionId.aliyun-cn-hangzhou
networkTypeStringNoConnection method. Default: public. Values: public, gateway, ssh, and private.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
instanceIdStringNoCloud instance ID.instance-001
instanceTypeStringNoInstance type.RDS
cloudInstanceTypeStringNoCloud instance access type.instance
vendorRegionIdStringNoCloud vendor region ID.cn-hangzhou
serverVersionStringNoDatabase server version.8.0
gatewayIdStringNoGateway ID used when networkType is gateway.gateway-001
tunnelIdStringNoPrivate connection ID.tunnel-001
accessIdStringNoCloud access credential ID.access-001
envStringNoEnvironment identifier selected by the request.product
sshConfigObjectNoSSH settings used when networkType is ssh.{}
multiTagStringNoMulti-active mark. The create API does not persist this field; use the update API instead.active
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"}

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.

When creating a DataHub data source with accessId, NineData uses the AccessKey and AccessKeySecret from that credential and overrides username and password in the request.

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
dataObjectDetails 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.