创建API
功能介绍
创建API。
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/service/apis
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方法请参见项目ID和账号ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token,使用Token认证时必选。通过调用IAM服务的“获取用户Token”接口获取响应消息头中X-Subject-Token的值。 |
workspace |
是 |
String |
工作空间ID,获取方法请参见实例ID和工作空间ID。 |
Dlm-Type |
否 |
String |
数据服务的版本类型,指定SHARED共享版或EXCLUSIVE专享版。 |
Content-Type |
是 |
String |
消息体的类型(格式),有Body体的情况下必选,没有Body体无需填写。如果请求消息体中含有中文字符,则需要通过charset=utf8指定中文字符集,例如取值为:application/json;charset=utf8。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
catalog_id |
否 |
String |
目录ID。 |
name |
否 |
String |
API名称。 |
description |
否 |
String |
API描述。 |
log_flag |
否 |
Boolean |
是否启用访问日志。 |
api_type |
否 |
String |
API类型。 枚举值:
|
auth_type |
否 |
String |
认证类型。 枚举值:
|
retention_period |
否 |
Integer |
最低保留期限,单位小时。 |
manager |
否 |
String |
API审核人。 |
path |
否 |
String |
API路径。 |
protocol |
否 |
String |
API请求协议类型。 枚举值:
|
request_type |
否 |
String |
请求类型。 枚举值:
|
tags |
否 |
Array of strings |
标签。 |
visibility |
否 |
String |
API可见性。 枚举值:
|
publish_type |
否 |
String |
发布类型(已弃用)。 枚举值:
|
data_mask_switch |
否 |
Boolean |
数据脱敏开关。 |
data_mask_paras |
否 |
Array of DataMaskParas objects |
数据脱敏配置。 |
body |
否 |
String |
请求体内容描述,仅注册类API使用。 |
datasource_config_list |
否 |
Array of DatasourceConfig objects |
多数据源配置信息,仅Groovy类API使用。 |
groovy_content |
否 |
String |
Groovy文本,仅Groovy类API使用。 |
request_paras |
否 |
Array of RequestPara objects |
API请求参数列表。 |
datasource_config |
否 |
DatasourceConfig object |
API数据源配置。 |
backend_config |
否 |
BackendConfig object |
API后端配置。仅注册类API使用 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
column_name |
否 |
String |
敏感字段。 |
algorithm_name |
否 |
String |
算法名称。 |
algorithm_type |
否 |
String |
算法类型。 |
en_name |
否 |
String |
算法名称。 |
algorithm_parameters |
否 |
String |
参数。 |
failure_policy |
否 |
String |
失败策略。 枚举值:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
否 |
String |
数据源的类型。 枚举值:
|
connection_name |
否 |
String |
数据连接名称。 |
connection_id |
否 |
String |
数据连接ID。 |
database |
否 |
String |
数据库名。 |
datatable |
否 |
String |
数据表名称。 |
table_id |
否 |
String |
数据表ID。 |
queue |
否 |
String |
DLI的队列名称。 |
access_mode |
否 |
String |
获取数据的模式。 枚举值:
|
access_type |
否 |
String |
取数方式(已弃用)。 枚举值:
|
pagination |
否 |
String |
分页方式。 枚举值:
|
sql |
否 |
String |
脚本模式下的SQL语句。 |
backend_paras |
否 |
Array of ApiRequestPara objects |
API后端参数。 |
response_paras |
否 |
Array of ApiResponsePara objects |
配置类API返回参数。 |
order_paras |
否 |
Array of DatasourceOrderPara objects |
排序参数。 |
total_size_sql |
否 |
String |
总条数计算脚本SQL。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
参数名。 |
position |
否 |
String |
参数的位置。 枚举值:
|
type |
否 |
String |
常量参数类型。 枚举值:
|
description |
否 |
String |
参数的描述。 |
necessary |
否 |
Boolean |
参数是否必填。 |
example_value |
否 |
String |
示例值。 |
default_value |
否 |
String |
默认值。 |
support_null |
否 |
Boolean |
支持NULL值。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
参数名称。 |
mapping |
否 |
String |
映射字段。 |
condition |
否 |
String |
操作符。 枚举值:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
参数名。 |
field |
否 |
String |
绑定的表字段。 |
type |
否 |
String |
常量参数类型。 枚举值:
|
description |
否 |
String |
参数描述。 |
example_value |
否 |
String |
参数示例值。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
排序参数名称。 |
field |
否 |
String |
对应的参数字段。 |
optional |
否 |
Boolean |
是否可选。 |
sort |
否 |
String |
排序方式。 枚举值:
|
order |
否 |
Integer |
排序参数顺序。 |
description |
否 |
String |
排序参数描述信息。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
否 |
String |
请求类型。
|
protocol |
否 |
String |
API请求协议类型。
|
host |
否 |
String |
后端HOST。 |
timeout |
否 |
Integer |
后端超时时间。 |
path |
否 |
String |
后端请求PATH。 |
backend_paras |
否 |
Array of BackendRequestPara objects |
API后端参数。 |
constant_paras |
否 |
Array of BackendConstant objects |
后端常量参数。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
API请求参数名称。 |
position |
否 |
String |
参数的位置。 枚举值:
|
backend_para_name |
否 |
String |
对应的后端参数。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
name |
否 |
String |
常量参数名。 |
type |
否 |
String |
常量参数类型。 枚举值:
|
position |
否 |
String |
参数的位置。 枚举值:
|
description |
否 |
String |
常量参数描述。 |
value |
否 |
String |
常量参数值。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
创建成功的API ID。 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误描述。 |
请求示例
-
创建配置类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" : [ ] }
-
创建脚本类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" : [ ] }
-
创建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" : [ ] }
响应示例
状态码: 200
Success。
{ "id" : "6b9e682fd6d0ef7c0f67470124b20762" }
SDK代码示例
SDK代码示例如下。
-
创建配置类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()); } } }
-
创建脚本类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()); } } }
-
创建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()); } } }
-
创建配置类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)
-
创建脚本类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)
-
创建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)
-
创建配置类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) } }
-
创建脚本类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) } }
-
创建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) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
Success。 |
400 |
BadRequest。 |