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
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| datasourceType | String | Yes | Data source type. Use a DatasourceType enabled in the target NineData environment, preserving the spelling shown by the product. | MONGODB |
| name | String | Yes | Specify the name of the data source. | Example MongoDB |
| username | String | Conditional | Database account. Whether it is required depends on the data source type. | <username> |
| password | String | Conditional | Database password. It has the same required conditions as username. | <password> |
| host | String | Yes | Connection address of the data source. | <DB_HOST> |
| port | Integer | No | Port number. Whether it is required depends on the data source type. | 27017 |
| envId | String | No | Environment. Call List Environments to get it. | <envId> |
| regionId | String | No | Region where the data source belongs. Call the List Regions API to get regionId. | <regionId> |
| networkType | String | No | Connection method. Values: public, gateway, ssh, and private. | public |
| masterName | String | No | Primary node name for a data source with a primary node. | master-1 |
| hostAndPorts | String | No | Comma-separated host:port pairs for multiple nodes, for example, Redis Sentinel or Cluster nodes. | host1:port1,host2:port2 |
| instanceId | String | No | Cloud instance ID. | <instanceId> |
| instanceType | String | No | Instance type. | RDS |
| cloudInstanceType | String | No | Cloud instance access type. | instance |
| vendorRegionId | String | No | Cloud vendor region ID. | cn-hangzhou |
| serverVersion | String | No | Database server version. | 8.0 |
| gatewayId | String | No | Gateway ID used when networkType is gateway. | <gatewayId> |
| tunnelId | String | No | Private connection ID. | <tunnelId> |
| accessId | String | No | Cloud access credential ID. | <accessId> |
| env | String | No | Environment identifier selected by the request. | <environment> |
| sshConfig | Object | No | SSH settings used when networkType is ssh. | {} |
| extraConfig | Object | No | Data-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.
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| mongoDBDeploymentType | String | No | MongoDB deployment type. Pass standalone for standalone mode. | standalone |
| authDB | String | Yes | Authentication 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
| Parameter | Type | Description | Example |
|---|---|---|---|
| success | Bool | Whether the API call was successful. Return values: true, false. | true |
| requestId | String | Request ID. | <requestId> |
| data | Object | Details 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.