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. Use a DatasourceType enabled in the target NineData environment, preserving the spelling shown by the product.MONGODB
nameStringYesSpecify the name of the data source.Example MongoDB
usernameStringConditionalDatabase account. Whether it is required depends on the data source type.<username>
passwordStringConditionalDatabase password. It has the same required conditions as username.<password>
hostStringYesConnection address of the data source.<DB_HOST>
portIntegerNoPort number. Whether it is required depends on the data source type.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. 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.<instanceId>
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.<gatewayId>
tunnelIdStringNoPrivate connection ID.<tunnelId>
accessIdStringNoCloud access credential ID.<accessId>
envStringNoEnvironment identifier selected by the request.<environment>
sshConfigObjectNoSSH settings used when networkType is ssh.{}
extraConfigObjectNoData-source-specific configuration. Put type-specific parameters in this object.{"authDB":"admin"}

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.

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

MongoDB standalone:

{
"name": "Example MongoDB",
"username": "<username>",
"password": "<password>",
"host": "<DB_HOST>",
"port": 27017,
"datasourceType": "MongoDB",
"regionId": "<regionId>",
"envId": "<envId>",
"networkType": "public",
"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": "public"
}

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.