Create an API
Function
Create an API.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/service/apis
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details about how to obtain the project ID, see Project ID and Account ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token. This parameter is mandatory when token authentication is used. You can obtain it from the value of X-Subject-Token in the response message header returned by the "Obtaining a User Token" API of the IAM service. |
workspace |
Yes |
String |
Workspace ID. For details about how to obtain the workspace ID, see Instance ID and Workspace ID. |
Dlm-Type |
No |
String |
Specifies the version type of the data service. The value can be SHARED or EXCLUSIVE. |
Content-Type |
Yes |
String |
Type (format) of the message body. This parameter is mandatory if the message body exists. If the message body does not exist, leave this parameter blank. If the request body contains Chinese characters, use charset=utf8 to specify the Chinese character set, for example, application/json;charset=utf8. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
catalog_id |
No |
String |
Catalog ID. |
name |
No |
String |
API name |
description |
No |
String |
API description |
log_flag |
No |
Boolean |
Indicates whether to enable the access log function. |
api_type |
No |
String |
API type Enumerated values:
|
auth_type |
No |
String |
Authentication mode Enumerated values:
|
retention_period |
No |
Integer |
Minimum retention period in hours |
manager |
No |
String |
API reviewer |
path |
No |
String |
API path |
protocol |
No |
String |
API request protocol type. Enumerated values:
|
request_type |
No |
String |
Request type Enumerated values:
|
tags |
No |
Array of strings |
Tag |
visibility |
No |
String |
API visibility Enumerated values:
|
publish_type |
No |
String |
Publishing type (obsolete) Enumerated values:
|
data_mask_switch |
No |
Boolean |
Whether to enable data masking |
data_mask_paras |
No |
Array of DataMaskParas objects |
Data masking poarameters |
body |
No |
String |
Request body description. It is available for registration APIs only. |
datasource_config_list |
No |
Array of DatasourceConfig objects |
Configuration of multiple data sources. It is available for Groovy APIs only. |
groovy_content |
No |
String |
Groovy text. It is available for Groovy APIs only. |
request_paras |
No |
Array of RequestPara objects |
List of API request parameters. |
datasource_config |
No |
DatasourceConfig object |
API data source configuration. |
backend_config |
No |
BackendConfig object |
API backend configuration. It is available for registration APIs only. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
column_name |
No |
String |
Sensitive field |
algorithm_name |
No |
String |
Algorithm name |
algorithm_type |
No |
String |
Algorithm type |
en_name |
No |
String |
Algorithm name |
algorithm_parameters |
No |
String |
Parameter |
failure_policy |
No |
String |
Failure policy Enumerated values:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Data source type. Enumerated values:
|
connection_name |
No |
String |
Name of a data connection. |
connection_id |
No |
String |
Data connection ID. |
database |
No |
String |
Indicates the database name. |
datatable |
No |
String |
Name of a data table. |
table_id |
No |
String |
Data table ID. |
queue |
No |
String |
Queue name of DLI. |
access_mode |
No |
String |
Mode for obtaining data Enumerated values:
|
access_type |
No |
String |
Mode for obtaining data (obsolete) Enumerated values:
|
pagination |
No |
String |
Pagination mode Enumerated values:
|
sql |
No |
String |
SQL statement in script mode |
backend_paras |
No |
Array of ApiRequestPara objects |
API backend parameter. |
response_paras |
No |
Array of ApiResponsePara objects |
Return parameters of configuration APIs. |
order_paras |
No |
Array of DatasourceOrderPara objects |
Sorting parameter. |
total_size_sql |
No |
String |
SQL script for calculating the total number of records |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Parameter name |
position |
No |
String |
Parameter position Enumerated values:
|
type |
No |
String |
Constant parameter type Enumerated values:
|
description |
No |
String |
Parameter description. |
necessary |
No |
Boolean |
Indicates whether a parameter is mandatory. |
example_value |
No |
String |
Example value |
default_value |
No |
String |
Default value. |
support_null |
No |
Boolean |
Null supported |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Parameter name |
mapping |
No |
String |
Mapping field. |
condition |
No |
String |
Operator Enumerated values:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Parameter name |
field |
No |
String |
Bound table field. |
type |
No |
String |
Constant parameter type Enumerated values:
|
description |
No |
String |
Parameter description. |
example_value |
No |
String |
Example value of a parameter. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Name of a sorting parameter. |
field |
No |
String |
Indicates the corresponding parameter field. |
optional |
No |
Boolean |
Indicates whether the parameter is optional. |
sort |
No |
String |
Sorting method Enumerated values:
|
order |
No |
Integer |
Sequence of sorting parameters. |
description |
No |
String |
Sorting parameter description |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Request type
|
protocol |
No |
String |
API request protocol type
|
host |
No |
String |
Backend host |
timeout |
No |
Integer |
Backend timeout interval. |
path |
No |
String |
Backend request path |
backend_paras |
No |
Array of BackendRequestPara objects |
API backend parameter. |
constant_paras |
No |
Array of BackendConstant objects |
Backend constant parameter. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
API request parameter name |
position |
No |
String |
Parameter position Enumerated values:
|
backend_para_name |
No |
String |
Backend parameter. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Name of a constant parameter. |
type |
No |
String |
Constant parameter type Enumerated values:
|
position |
No |
String |
Parameter position Enumerated values:
|
description |
No |
String |
Constant parameter description. |
value |
No |
String |
Constant parameter value. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
id |
String |
ID of the API that is successfully created. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Example Requests
-
Create a configuration API.
/v1/0833a5737480d53b2f250010d01a7b88/service/apis { "catalog_id" : "0", "name" : "create_config_api", "description" : "dws", "visibility" : "WORKSPACE", "api_type" : "API_SPECIFIC_TYPE_CONFIGURATION", "auth_type" : "APP", "retention_period" : "1", "manager" : "user", "log_flag" : true, "path" : "/pathrGW6riuO/{p}", "protocol" : "PROTOCOL_TYPE_HTTPS", "request_type" : "REQUEST_TYPE_POST", "request_paras" : [ { "name" : "a", "position" : "REQUEST_PARAMETER_POSITION_QUERY", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "b", "position" : "REQUEST_PARAMETER_POSITION_HEADER", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "c", "position" : "REQUEST_PARAMETER_POSITION_BODY", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "p", "position" : "REQUEST_PARAMETER_POSITION_PATH", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "ok1", "necessary" : true, "example_value" : "ok1", "default_value" : "ok1", "support_null" : false } ], "datasource_config" : { "access_mode" : "SQL", "order_paras" : [ ], "table_id" : "NativeTable-c68d84bd2d89420cb2458b4e06805ddf-postgres-dbadmin-test3", "datatable" : "dbadmin.test3", "database" : "postgres", "connection_id" : "c68d84bd2d89420cb2458b4e06805ddf", "connection_name" : "yqp_dws", "type" : "DWS", "pagination" : "DEFAULT", "sql" : "", "total_size_sql" : "", "backend_paras" : [ { "name" : "a", "mapping" : "username", "condition" : "CONDITION_TYPE_EQ" } ], "response_paras" : [ { "description" : "", "example_value" : "", "field" : "id_num", "name" : "id_num", "type" : "REQUEST_PARAMETER_TYPE_STRING" }, { "description" : "", "example_value" : "", "field" : "username", "name" : "username", "type" : "REQUEST_PARAMETER_TYPE_STRING" } ] }, "data_mask_switch" : false, "data_mask_paras" : [ ] }
-
Create a script API.
/v1/0833a5737480d53b2f250010d01a7b88/service/apis { "catalog_id" : "0", "name" : "create_script_api", "description" : "dws", "visibility" : "WORKSPACE", "api_type" : "API_SPECIFIC_TYPE_SCRIPT", "auth_type" : "APP", "retention_period" : "1", "manager" : "user", "log_flag" : true, "path" : "/pathR7YL3xfN/{p}", "protocol" : "PROTOCOL_TYPE_HTTPS", "request_type" : "REQUEST_TYPE_POST", "request_paras" : [ { "name" : "a", "position" : "REQUEST_PARAMETER_POSITION_QUERY", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "b", "position" : "REQUEST_PARAMETER_POSITION_HEADER", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "c", "position" : "REQUEST_PARAMETER_POSITION_BODY", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false }, { "name" : "p", "position" : "REQUEST_PARAMETER_POSITION_PATH", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "ok1", "necessary" : true, "example_value" : "ok1", "default_value" : "ok1", "support_null" : false } ], "datasource_config" : { "access_mode" : "SQL", "order_paras" : [ ], "database" : "dls", "connection_id" : "c68d84bd2d89420cb2458b4e06805ddf", "connection_name" : "yqp_dws", "type" : "DWS", "pagination" : "CUSTOM", "sql" : "c2VsZWN0IDMsNCw1", "total_size_sql" : "", "backend_paras" : [ { "name" : "a", "mapping" : "a", "condition" : "CONDITION_TYPE_EQ" }, { "name" : "b", "mapping" : "b", "condition" : "CONDITION_TYPE_EQ" }, { "name" : "c", "mapping" : "c", "condition" : "CONDITION_TYPE_EQ" }, { "name" : "p", "mapping" : "p", "condition" : "CONDITION_TYPE_EQ" } ] }, "data_mask_switch" : false, "data_mask_paras" : [ ] }
-
Create a MyBatis API.
/v1/0833a5737480d53b2f250010d01a7b88/service/apis { "catalog_id" : "0", "name" : "create_mybatis_api", "description" : "desc", "visibility" : "WORKSPACE", "api_type" : "API_SPECIFIC_TYPE_MYBATIS", "auth_type" : "APP", "retention_period" : "0", "manager" : "user", "log_flag" : true, "path" : "/pathR7YL3xfN", "protocol" : "PROTOCOL_TYPE_HTTPS", "request_type" : "REQUEST_TYPE_POST", "request_paras" : [ { "name" : "ssss", "position" : "REQUEST_PARAMETER_POSITION_QUERY", "type" : "REQUEST_PARAMETER_TYPE_STRING", "description" : "1", "necessary" : true, "example_value" : "1", "default_value" : "1", "support_null" : false } ], "datasource_config" : { "access_mode" : "SQL", "order_paras" : [ ], "database" : "dls", "connection_id" : "c68d84bd2d89420cb2458b4e06805ddf", "connection_name" : "yqp_dws", "type" : "DWS", "pagination" : "CUSTOM", "sql" : "c2VsZWN0IDEKPGlmIHRlc3Q9InNzc3MgPT0gJzEnLnRvU3RyaW5nKCkiPiAgCiwyIAo8L2lmPg==", "total_size_sql" : "", "backend_paras" : [ ] }, "data_mask_switch" : false, "data_mask_paras" : [ ] }
Example Responses
Status code: 200
Success
{ "id" : "6b9e682fd6d0ef7c0f67470124b20762" }
SDK Sample Code
The SDK sample code is as follows.
-
Create a configuration API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion; import com.huaweicloud.sdk.dataartsstudio.v1.*; import com.huaweicloud.sdk.dataartsstudio.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateApiSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); DataArtsStudioClient client = DataArtsStudioClient.newBuilder() .withCredential(auth) .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>")) .build(); CreateApiRequest request = new CreateApiRequest(); Api body = new Api(); List<ApiResponsePara> listDatasourceConfigResponseParas = new ArrayList<>(); listDatasourceConfigResponseParas.add( new ApiResponsePara() .withName("id_num") .withField("id_num") .withType(ApiResponsePara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("") .withExampleValue("") ); listDatasourceConfigResponseParas.add( new ApiResponsePara() .withName("username") .withField("username") .withType(ApiResponsePara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("") .withExampleValue("") ); List<ApiRequestPara> listDatasourceConfigBackendParas = new ArrayList<>(); listDatasourceConfigBackendParas.add( new ApiRequestPara() .withName("a") .withMapping("username") .withCondition(ApiRequestPara.ConditionEnum.fromValue("CONDITION_TYPE_EQ")) ); DatasourceConfig datasourceConfigbody = new DatasourceConfig(); datasourceConfigbody.withType(DatasourceConfig.TypeEnum.fromValue("DWS")) .withConnectionName("yqp_dws") .withConnectionId("c68d84bd2d89420cb2458b4e06805ddf") .withDatabase("postgres") .withDatatable("dbadmin.test3") .withTableId("NativeTable-c68d84bd2d89420cb2458b4e06805ddf-postgres-dbadmin-test3") .withAccessMode(DatasourceConfig.AccessModeEnum.fromValue("SQL")) .withPagination(DatasourceConfig.PaginationEnum.fromValue("DEFAULT")) .withSql("") .withBackendParas(listDatasourceConfigBackendParas) .withResponseParas(listDatasourceConfigResponseParas); List<RequestPara> listbodyRequestParas = new ArrayList<>(); listbodyRequestParas.add( new RequestPara() .withName("a") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_QUERY")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("b") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_HEADER")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("c") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_BODY")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("p") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_PATH")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("ok1") .withNecessary(true) .withExampleValue("ok1") .withDefaultValue("ok1") ); body.withDatasourceConfig(datasourceConfigbody); body.withRequestParas(listbodyRequestParas); body.withVisibility(Api.VisibilityEnum.fromValue("WORKSPACE")); body.withRequestType(Api.RequestTypeEnum.fromValue("REQUEST_TYPE_POST")); body.withProtocol(Api.ProtocolEnum.fromValue("PROTOCOL_TYPE_HTTPS")); body.withPath("/pathrGW6riuO/{p}"); body.withManager("user"); body.withAuthType(Api.AuthTypeEnum.fromValue("APP")); body.withApiType(Api.ApiTypeEnum.fromValue("API_SPECIFIC_TYPE_CONFIGURATION")); body.withLogFlag(true); body.withDescription("dws"); body.withName("create_config_api"); body.withCatalogId("0"); request.withBody(body); try { CreateApiResponse response = client.createApi(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Create a script API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion; import com.huaweicloud.sdk.dataartsstudio.v1.*; import com.huaweicloud.sdk.dataartsstudio.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateApiSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); DataArtsStudioClient client = DataArtsStudioClient.newBuilder() .withCredential(auth) .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>")) .build(); CreateApiRequest request = new CreateApiRequest(); Api body = new Api(); List<ApiRequestPara> listDatasourceConfigBackendParas = new ArrayList<>(); listDatasourceConfigBackendParas.add( new ApiRequestPara() .withName("a") .withMapping("a") .withCondition(ApiRequestPara.ConditionEnum.fromValue("CONDITION_TYPE_EQ")) ); listDatasourceConfigBackendParas.add( new ApiRequestPara() .withName("b") .withMapping("b") .withCondition(ApiRequestPara.ConditionEnum.fromValue("CONDITION_TYPE_EQ")) ); listDatasourceConfigBackendParas.add( new ApiRequestPara() .withName("c") .withMapping("c") .withCondition(ApiRequestPara.ConditionEnum.fromValue("CONDITION_TYPE_EQ")) ); listDatasourceConfigBackendParas.add( new ApiRequestPara() .withName("p") .withMapping("p") .withCondition(ApiRequestPara.ConditionEnum.fromValue("CONDITION_TYPE_EQ")) ); DatasourceConfig datasourceConfigbody = new DatasourceConfig(); datasourceConfigbody.withType(DatasourceConfig.TypeEnum.fromValue("DWS")) .withConnectionName("yqp_dws") .withConnectionId("c68d84bd2d89420cb2458b4e06805ddf") .withDatabase("dls") .withAccessMode(DatasourceConfig.AccessModeEnum.fromValue("SQL")) .withPagination(DatasourceConfig.PaginationEnum.fromValue("CUSTOM")) .withSql("c2VsZWN0IDMsNCw1") .withBackendParas(listDatasourceConfigBackendParas); List<RequestPara> listbodyRequestParas = new ArrayList<>(); listbodyRequestParas.add( new RequestPara() .withName("a") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_QUERY")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("b") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_HEADER")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("c") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_BODY")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); listbodyRequestParas.add( new RequestPara() .withName("p") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_PATH")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("ok1") .withNecessary(true) .withExampleValue("ok1") .withDefaultValue("ok1") ); body.withDatasourceConfig(datasourceConfigbody); body.withRequestParas(listbodyRequestParas); body.withVisibility(Api.VisibilityEnum.fromValue("WORKSPACE")); body.withRequestType(Api.RequestTypeEnum.fromValue("REQUEST_TYPE_POST")); body.withProtocol(Api.ProtocolEnum.fromValue("PROTOCOL_TYPE_HTTPS")); body.withPath("/pathR7YL3xfN/{p}"); body.withManager("user"); body.withAuthType(Api.AuthTypeEnum.fromValue("APP")); body.withApiType(Api.ApiTypeEnum.fromValue("API_SPECIFIC_TYPE_SCRIPT")); body.withLogFlag(true); body.withDescription("dws"); body.withName("create_script_api"); body.withCatalogId("0"); request.withBody(body); try { CreateApiResponse response = client.createApi(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Create a MyBatis API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion; import com.huaweicloud.sdk.dataartsstudio.v1.*; import com.huaweicloud.sdk.dataartsstudio.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateApiSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); DataArtsStudioClient client = DataArtsStudioClient.newBuilder() .withCredential(auth) .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>")) .build(); CreateApiRequest request = new CreateApiRequest(); Api body = new Api(); DatasourceConfig datasourceConfigbody = new DatasourceConfig(); datasourceConfigbody.withType(DatasourceConfig.TypeEnum.fromValue("DWS")) .withConnectionName("yqp_dws") .withConnectionId("c68d84bd2d89420cb2458b4e06805ddf") .withDatabase("dls") .withAccessMode(DatasourceConfig.AccessModeEnum.fromValue("SQL")) .withPagination(DatasourceConfig.PaginationEnum.fromValue("CUSTOM")) .withSql("c2VsZWN0IDEKPGlmIHRlc3Q9InNzc3MgPT0gJzEnLnRvU3RyaW5nKCkiPiAgCiwyIAo8L2lmPg=="); List<RequestPara> listbodyRequestParas = new ArrayList<>(); listbodyRequestParas.add( new RequestPara() .withName("ssss") .withPosition(RequestPara.PositionEnum.fromValue("REQUEST_PARAMETER_POSITION_QUERY")) .withType(RequestPara.TypeEnum.fromValue("REQUEST_PARAMETER_TYPE_STRING")) .withDescription("1") .withNecessary(true) .withExampleValue("1") .withDefaultValue("1") ); body.withDatasourceConfig(datasourceConfigbody); body.withRequestParas(listbodyRequestParas); body.withVisibility(Api.VisibilityEnum.fromValue("WORKSPACE")); body.withRequestType(Api.RequestTypeEnum.fromValue("REQUEST_TYPE_POST")); body.withProtocol(Api.ProtocolEnum.fromValue("PROTOCOL_TYPE_HTTPS")); body.withPath("/pathR7YL3xfN"); body.withManager("user"); body.withAuthType(Api.AuthTypeEnum.fromValue("APP")); body.withApiType(Api.ApiTypeEnum.fromValue("API_SPECIFIC_TYPE_MYBATIS")); body.withLogFlag(true); body.withDescription("desc"); body.withName("create_mybatis_api"); body.withCatalogId("0"); request.withBody(body); try { CreateApiResponse response = client.createApi(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Create a configuration API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdataartsstudio.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = DataArtsStudioClient.new_builder() \ .with_credentials(credentials) \ .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateApiRequest() listResponseParasDatasourceConfig = [ ApiResponsePara( name="id_num", field="id_num", type="REQUEST_PARAMETER_TYPE_STRING", description="", example_value="" ), ApiResponsePara( name="username", field="username", type="REQUEST_PARAMETER_TYPE_STRING", description="", example_value="" ) ] listBackendParasDatasourceConfig = [ ApiRequestPara( name="a", mapping="username", condition="CONDITION_TYPE_EQ" ) ] datasourceConfigbody = DatasourceConfig( type="DWS", connection_name="yqp_dws", connection_id="c68d84bd2d89420cb2458b4e06805ddf", database="postgres", datatable="dbadmin.test3", table_id="NativeTable-c68d84bd2d89420cb2458b4e06805ddf-postgres-dbadmin-test3", access_mode="SQL", pagination="DEFAULT", sql="", backend_paras=listBackendParasDatasourceConfig, response_paras=listResponseParasDatasourceConfig ) listRequestParasbody = [ RequestPara( name="a", position="REQUEST_PARAMETER_POSITION_QUERY", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="b", position="REQUEST_PARAMETER_POSITION_HEADER", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="c", position="REQUEST_PARAMETER_POSITION_BODY", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="p", position="REQUEST_PARAMETER_POSITION_PATH", type="REQUEST_PARAMETER_TYPE_STRING", description="ok1", necessary=True, example_value="ok1", default_value="ok1" ) ] request.body = Api( datasource_config=datasourceConfigbody, request_paras=listRequestParasbody, visibility="WORKSPACE", request_type="REQUEST_TYPE_POST", protocol="PROTOCOL_TYPE_HTTPS", path="/pathrGW6riuO/{p}", manager="user", auth_type="APP", api_type="API_SPECIFIC_TYPE_CONFIGURATION", log_flag=True, description="dws", name="create_config_api", catalog_id="0" ) response = client.create_api(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Create a script API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdataartsstudio.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = DataArtsStudioClient.new_builder() \ .with_credentials(credentials) \ .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateApiRequest() listBackendParasDatasourceConfig = [ ApiRequestPara( name="a", mapping="a", condition="CONDITION_TYPE_EQ" ), ApiRequestPara( name="b", mapping="b", condition="CONDITION_TYPE_EQ" ), ApiRequestPara( name="c", mapping="c", condition="CONDITION_TYPE_EQ" ), ApiRequestPara( name="p", mapping="p", condition="CONDITION_TYPE_EQ" ) ] datasourceConfigbody = DatasourceConfig( type="DWS", connection_name="yqp_dws", connection_id="c68d84bd2d89420cb2458b4e06805ddf", database="dls", access_mode="SQL", pagination="CUSTOM", sql="c2VsZWN0IDMsNCw1", backend_paras=listBackendParasDatasourceConfig ) listRequestParasbody = [ RequestPara( name="a", position="REQUEST_PARAMETER_POSITION_QUERY", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="b", position="REQUEST_PARAMETER_POSITION_HEADER", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="c", position="REQUEST_PARAMETER_POSITION_BODY", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ), RequestPara( name="p", position="REQUEST_PARAMETER_POSITION_PATH", type="REQUEST_PARAMETER_TYPE_STRING", description="ok1", necessary=True, example_value="ok1", default_value="ok1" ) ] request.body = Api( datasource_config=datasourceConfigbody, request_paras=listRequestParasbody, visibility="WORKSPACE", request_type="REQUEST_TYPE_POST", protocol="PROTOCOL_TYPE_HTTPS", path="/pathR7YL3xfN/{p}", manager="user", auth_type="APP", api_type="API_SPECIFIC_TYPE_SCRIPT", log_flag=True, description="dws", name="create_script_api", catalog_id="0" ) response = client.create_api(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Create a MyBatis API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdataartsstudio.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = DataArtsStudioClient.new_builder() \ .with_credentials(credentials) \ .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateApiRequest() datasourceConfigbody = DatasourceConfig( type="DWS", connection_name="yqp_dws", connection_id="c68d84bd2d89420cb2458b4e06805ddf", database="dls", access_mode="SQL", pagination="CUSTOM", sql="c2VsZWN0IDEKPGlmIHRlc3Q9InNzc3MgPT0gJzEnLnRvU3RyaW5nKCkiPiAgCiwyIAo8L2lmPg==" ) listRequestParasbody = [ RequestPara( name="ssss", position="REQUEST_PARAMETER_POSITION_QUERY", type="REQUEST_PARAMETER_TYPE_STRING", description="1", necessary=True, example_value="1", default_value="1" ) ] request.body = Api( datasource_config=datasourceConfigbody, request_paras=listRequestParasbody, visibility="WORKSPACE", request_type="REQUEST_TYPE_POST", protocol="PROTOCOL_TYPE_HTTPS", path="/pathR7YL3xfN", manager="user", auth_type="APP", api_type="API_SPECIFIC_TYPE_MYBATIS", log_flag=True, description="desc", name="create_mybatis_api", catalog_id="0" ) response = client.create_api(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Create a configuration API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := dataartsstudio.NewDataArtsStudioClient( dataartsstudio.DataArtsStudioClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateApiRequest{} nameResponseParas:= "id_num" fieldResponseParas:= "id_num" typeResponseParas:= model.GetApiResponseParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionResponseParas:= "" exampleValueResponseParas:= "" nameResponseParas1:= "username" fieldResponseParas1:= "username" typeResponseParas1:= model.GetApiResponseParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionResponseParas1:= "" exampleValueResponseParas1:= "" var listResponseParasDatasourceConfig = []model.ApiResponsePara{ { Name: &nameResponseParas, Field: &fieldResponseParas, Type: &typeResponseParas, Description: &descriptionResponseParas, ExampleValue: &exampleValueResponseParas, }, { Name: &nameResponseParas1, Field: &fieldResponseParas1, Type: &typeResponseParas1, Description: &descriptionResponseParas1, ExampleValue: &exampleValueResponseParas1, }, } nameBackendParas:= "a" mappingBackendParas:= "username" conditionBackendParas:= model.GetApiRequestParaConditionEnum().CONDITION_TYPE_EQ var listBackendParasDatasourceConfig = []model.ApiRequestPara{ { Name: &nameBackendParas, Mapping: &mappingBackendParas, Condition: &conditionBackendParas, }, } typeDatasourceConfig:= model.GetDatasourceConfigTypeEnum().DWS connectionNameDatasourceConfig:= "yqp_dws" connectionIdDatasourceConfig:= "c68d84bd2d89420cb2458b4e06805ddf" databaseDatasourceConfig:= "postgres" datatableDatasourceConfig:= "dbadmin.test3" tableIdDatasourceConfig:= "NativeTable-c68d84bd2d89420cb2458b4e06805ddf-postgres-dbadmin-test3" accessModeDatasourceConfig:= model.GetDatasourceConfigAccessModeEnum().SQL paginationDatasourceConfig:= model.GetDatasourceConfigPaginationEnum().DEFAULT sqlDatasourceConfig:= "" datasourceConfigbody := &model.DatasourceConfig{ Type: &typeDatasourceConfig, ConnectionName: &connectionNameDatasourceConfig, ConnectionId: &connectionIdDatasourceConfig, Database: &databaseDatasourceConfig, Datatable: &datatableDatasourceConfig, TableId: &tableIdDatasourceConfig, AccessMode: &accessModeDatasourceConfig, Pagination: &paginationDatasourceConfig, Sql: &sqlDatasourceConfig, BackendParas: &listBackendParasDatasourceConfig, ResponseParas: &listResponseParasDatasourceConfig, } nameRequestParas:= "a" positionRequestParas:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_QUERY typeRequestParas:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas:= "1" necessaryRequestParas:= true exampleValueRequestParas:= "1" defaultValueRequestParas:= "1" nameRequestParas1:= "b" positionRequestParas1:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_HEADER typeRequestParas1:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas1:= "1" necessaryRequestParas1:= true exampleValueRequestParas1:= "1" defaultValueRequestParas1:= "1" nameRequestParas2:= "c" positionRequestParas2:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_BODY typeRequestParas2:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas2:= "1" necessaryRequestParas2:= true exampleValueRequestParas2:= "1" defaultValueRequestParas2:= "1" nameRequestParas3:= "p" positionRequestParas3:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_PATH typeRequestParas3:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas3:= "ok1" necessaryRequestParas3:= true exampleValueRequestParas3:= "ok1" defaultValueRequestParas3:= "ok1" var listRequestParasbody = []model.RequestPara{ { Name: &nameRequestParas, Position: &positionRequestParas, Type: &typeRequestParas, Description: &descriptionRequestParas, Necessary: &necessaryRequestParas, ExampleValue: &exampleValueRequestParas, DefaultValue: &defaultValueRequestParas, }, { Name: &nameRequestParas1, Position: &positionRequestParas1, Type: &typeRequestParas1, Description: &descriptionRequestParas1, Necessary: &necessaryRequestParas1, ExampleValue: &exampleValueRequestParas1, DefaultValue: &defaultValueRequestParas1, }, { Name: &nameRequestParas2, Position: &positionRequestParas2, Type: &typeRequestParas2, Description: &descriptionRequestParas2, Necessary: &necessaryRequestParas2, ExampleValue: &exampleValueRequestParas2, DefaultValue: &defaultValueRequestParas2, }, { Name: &nameRequestParas3, Position: &positionRequestParas3, Type: &typeRequestParas3, Description: &descriptionRequestParas3, Necessary: &necessaryRequestParas3, ExampleValue: &exampleValueRequestParas3, DefaultValue: &defaultValueRequestParas3, }, } visibilityApi:= model.GetApiVisibilityEnum().WORKSPACE requestTypeApi:= model.GetApiRequestTypeEnum().REQUEST_TYPE_POST protocolApi:= model.GetApiProtocolEnum().PROTOCOL_TYPE_HTTPS pathApi:= "/pathrGW6riuO/{p}" managerApi:= "user" authTypeApi:= model.GetApiAuthTypeEnum().APP apiTypeApi:= model.GetApiApiTypeEnum().API_SPECIFIC_TYPE_CONFIGURATION logFlagApi:= true descriptionApi:= "dws" nameApi:= "create_config_api" catalogIdApi:= "0" request.Body = &model.Api{ DatasourceConfig: datasourceConfigbody, RequestParas: &listRequestParasbody, Visibility: &visibilityApi, RequestType: &requestTypeApi, Protocol: &protocolApi, Path: &pathApi, Manager: &managerApi, AuthType: &authTypeApi, ApiType: &apiTypeApi, LogFlag: &logFlagApi, Description: &descriptionApi, Name: &nameApi, CatalogId: &catalogIdApi, } response, err := client.CreateApi(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Create a script API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := dataartsstudio.NewDataArtsStudioClient( dataartsstudio.DataArtsStudioClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateApiRequest{} nameBackendParas:= "a" mappingBackendParas:= "a" conditionBackendParas:= model.GetApiRequestParaConditionEnum().CONDITION_TYPE_EQ nameBackendParas1:= "b" mappingBackendParas1:= "b" conditionBackendParas1:= model.GetApiRequestParaConditionEnum().CONDITION_TYPE_EQ nameBackendParas2:= "c" mappingBackendParas2:= "c" conditionBackendParas2:= model.GetApiRequestParaConditionEnum().CONDITION_TYPE_EQ nameBackendParas3:= "p" mappingBackendParas3:= "p" conditionBackendParas3:= model.GetApiRequestParaConditionEnum().CONDITION_TYPE_EQ var listBackendParasDatasourceConfig = []model.ApiRequestPara{ { Name: &nameBackendParas, Mapping: &mappingBackendParas, Condition: &conditionBackendParas, }, { Name: &nameBackendParas1, Mapping: &mappingBackendParas1, Condition: &conditionBackendParas1, }, { Name: &nameBackendParas2, Mapping: &mappingBackendParas2, Condition: &conditionBackendParas2, }, { Name: &nameBackendParas3, Mapping: &mappingBackendParas3, Condition: &conditionBackendParas3, }, } typeDatasourceConfig:= model.GetDatasourceConfigTypeEnum().DWS connectionNameDatasourceConfig:= "yqp_dws" connectionIdDatasourceConfig:= "c68d84bd2d89420cb2458b4e06805ddf" databaseDatasourceConfig:= "dls" accessModeDatasourceConfig:= model.GetDatasourceConfigAccessModeEnum().SQL paginationDatasourceConfig:= model.GetDatasourceConfigPaginationEnum().CUSTOM sqlDatasourceConfig:= "c2VsZWN0IDMsNCw1" datasourceConfigbody := &model.DatasourceConfig{ Type: &typeDatasourceConfig, ConnectionName: &connectionNameDatasourceConfig, ConnectionId: &connectionIdDatasourceConfig, Database: &databaseDatasourceConfig, AccessMode: &accessModeDatasourceConfig, Pagination: &paginationDatasourceConfig, Sql: &sqlDatasourceConfig, BackendParas: &listBackendParasDatasourceConfig, } nameRequestParas:= "a" positionRequestParas:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_QUERY typeRequestParas:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas:= "1" necessaryRequestParas:= true exampleValueRequestParas:= "1" defaultValueRequestParas:= "1" nameRequestParas1:= "b" positionRequestParas1:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_HEADER typeRequestParas1:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas1:= "1" necessaryRequestParas1:= true exampleValueRequestParas1:= "1" defaultValueRequestParas1:= "1" nameRequestParas2:= "c" positionRequestParas2:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_BODY typeRequestParas2:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas2:= "1" necessaryRequestParas2:= true exampleValueRequestParas2:= "1" defaultValueRequestParas2:= "1" nameRequestParas3:= "p" positionRequestParas3:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_PATH typeRequestParas3:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas3:= "ok1" necessaryRequestParas3:= true exampleValueRequestParas3:= "ok1" defaultValueRequestParas3:= "ok1" var listRequestParasbody = []model.RequestPara{ { Name: &nameRequestParas, Position: &positionRequestParas, Type: &typeRequestParas, Description: &descriptionRequestParas, Necessary: &necessaryRequestParas, ExampleValue: &exampleValueRequestParas, DefaultValue: &defaultValueRequestParas, }, { Name: &nameRequestParas1, Position: &positionRequestParas1, Type: &typeRequestParas1, Description: &descriptionRequestParas1, Necessary: &necessaryRequestParas1, ExampleValue: &exampleValueRequestParas1, DefaultValue: &defaultValueRequestParas1, }, { Name: &nameRequestParas2, Position: &positionRequestParas2, Type: &typeRequestParas2, Description: &descriptionRequestParas2, Necessary: &necessaryRequestParas2, ExampleValue: &exampleValueRequestParas2, DefaultValue: &defaultValueRequestParas2, }, { Name: &nameRequestParas3, Position: &positionRequestParas3, Type: &typeRequestParas3, Description: &descriptionRequestParas3, Necessary: &necessaryRequestParas3, ExampleValue: &exampleValueRequestParas3, DefaultValue: &defaultValueRequestParas3, }, } visibilityApi:= model.GetApiVisibilityEnum().WORKSPACE requestTypeApi:= model.GetApiRequestTypeEnum().REQUEST_TYPE_POST protocolApi:= model.GetApiProtocolEnum().PROTOCOL_TYPE_HTTPS pathApi:= "/pathR7YL3xfN/{p}" managerApi:= "user" authTypeApi:= model.GetApiAuthTypeEnum().APP apiTypeApi:= model.GetApiApiTypeEnum().API_SPECIFIC_TYPE_SCRIPT logFlagApi:= true descriptionApi:= "dws" nameApi:= "create_script_api" catalogIdApi:= "0" request.Body = &model.Api{ DatasourceConfig: datasourceConfigbody, RequestParas: &listRequestParasbody, Visibility: &visibilityApi, RequestType: &requestTypeApi, Protocol: &protocolApi, Path: &pathApi, Manager: &managerApi, AuthType: &authTypeApi, ApiType: &apiTypeApi, LogFlag: &logFlagApi, Description: &descriptionApi, Name: &nameApi, CatalogId: &catalogIdApi, } response, err := client.CreateApi(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Create a MyBatis API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := dataartsstudio.NewDataArtsStudioClient( dataartsstudio.DataArtsStudioClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateApiRequest{} typeDatasourceConfig:= model.GetDatasourceConfigTypeEnum().DWS connectionNameDatasourceConfig:= "yqp_dws" connectionIdDatasourceConfig:= "c68d84bd2d89420cb2458b4e06805ddf" databaseDatasourceConfig:= "dls" accessModeDatasourceConfig:= model.GetDatasourceConfigAccessModeEnum().SQL paginationDatasourceConfig:= model.GetDatasourceConfigPaginationEnum().CUSTOM sqlDatasourceConfig:= "c2VsZWN0IDEKPGlmIHRlc3Q9InNzc3MgPT0gJzEnLnRvU3RyaW5nKCkiPiAgCiwyIAo8L2lmPg==" datasourceConfigbody := &model.DatasourceConfig{ Type: &typeDatasourceConfig, ConnectionName: &connectionNameDatasourceConfig, ConnectionId: &connectionIdDatasourceConfig, Database: &databaseDatasourceConfig, AccessMode: &accessModeDatasourceConfig, Pagination: &paginationDatasourceConfig, Sql: &sqlDatasourceConfig, } nameRequestParas:= "ssss" positionRequestParas:= model.GetRequestParaPositionEnum().REQUEST_PARAMETER_POSITION_QUERY typeRequestParas:= model.GetRequestParaTypeEnum().REQUEST_PARAMETER_TYPE_STRING descriptionRequestParas:= "1" necessaryRequestParas:= true exampleValueRequestParas:= "1" defaultValueRequestParas:= "1" var listRequestParasbody = []model.RequestPara{ { Name: &nameRequestParas, Position: &positionRequestParas, Type: &typeRequestParas, Description: &descriptionRequestParas, Necessary: &necessaryRequestParas, ExampleValue: &exampleValueRequestParas, DefaultValue: &defaultValueRequestParas, }, } visibilityApi:= model.GetApiVisibilityEnum().WORKSPACE requestTypeApi:= model.GetApiRequestTypeEnum().REQUEST_TYPE_POST protocolApi:= model.GetApiProtocolEnum().PROTOCOL_TYPE_HTTPS pathApi:= "/pathR7YL3xfN" managerApi:= "user" authTypeApi:= model.GetApiAuthTypeEnum().APP apiTypeApi:= model.GetApiApiTypeEnum().API_SPECIFIC_TYPE_MYBATIS logFlagApi:= true descriptionApi:= "desc" nameApi:= "create_mybatis_api" catalogIdApi:= "0" request.Body = &model.Api{ DatasourceConfig: datasourceConfigbody, RequestParas: &listRequestParasbody, Visibility: &visibilityApi, RequestType: &requestTypeApi, Protocol: &protocolApi, Path: &pathApi, Manager: &managerApi, AuthType: &authTypeApi, ApiType: &apiTypeApi, LogFlag: &logFlagApi, Description: &descriptionApi, Name: &nameApi, CatalogId: &catalogIdApi, } response, err := client.CreateApi(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
Success |
400 |
Bad request |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot