更新时间:2024-11-22 GMT+08:00

创建API

功能介绍

创建API。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/service/apis

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方法请参见项目ID和账号ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

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。

表3 请求Body参数

参数

是否必选

参数类型

描述

catalog_id

String

目录ID。

name

String

API名称。

description

String

API描述。

log_flag

Boolean

是否启用访问日志。

api_type

String

API类型。

枚举值:

  • API_SPECIFIC_TYPE_CONFIGURATION: 配置类API

  • API_SPECIFIC_TYPE_SCRIPT: 脚本类API

  • API_SPECIFIC_TYPE_MYBATIS: MyBatis类API

  • API_SPECIFIC_TYPE_GROOVY: Groovy类API

  • API_SPECIFIC_TYPE_REGISTER:注册类API

  • API_SPECIFIC_TYPE_ORCHESTRATE:编排类API

  • API_TYPE_CREATE:创建类API(已弃用)

  • API_TYPE_REGISTER:注册类API(已弃用)

auth_type

String

认证类型。

枚举值:

  • APP: app secret认证

  • IAM: IAM token认证

  • NONE: 无认证

retention_period

Integer

最低保留期限,单位小时。

manager

String

API审核人。

path

String

API路径。

protocol

String

API请求协议类型。

枚举值:

  • PROTOCOL_TYPE_HTTP:HTTP协议请求

  • PROTOCOL_TYPE_HTTPS:HTTPS协议请求

request_type

String

请求类型。

枚举值:

  • REQUEST_TYPE_POST:POST请求

  • REQUEST_TYPE_GET:GET请求

tags

Array of strings

标签。

visibility

String

API可见性。

枚举值:

  • WORKSPACE: 工作空间可见

  • PROJECT: 项目可见

  • DOMAIN: 租户可见

publish_type

String

发布类型(已弃用)。

枚举值:

  • PUBLISH_TYPE_PUBLIC:公开

  • PUBLISH_TYPE_PRIVATE:私有

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使用

表4 DataMaskParas

参数

是否必选

参数类型

描述

column_name

String

敏感字段。

algorithm_name

String

算法名称。

algorithm_type

String

算法类型。

en_name

String

算法名称。

algorithm_parameters

String

参数。

failure_policy

String

失败策略。

枚举值:

  • SKIP:跳过, 即不做处理

  • INTERRUPT_AND_EXCEPTION:中断并抛出异常

  • SET_NULL:置空

  • DEFAULT_VALUE:默认值

表5 DatasourceConfig

参数

是否必选

参数类型

描述

type

String

数据源的类型。

枚举值:

  • MYSQL:MYSQL数据源

  • DLI:DLI数据源

  • DWS:DWS数据源

  • HIVE:HIVE数据源

  • HBASE:HBASE数据源

connection_name

String

数据连接名称。

connection_id

String

数据连接ID。

database

String

数据库名。

datatable

String

数据表名称。

table_id

String

数据表ID。

queue

String

DLI的队列名称。

access_mode

String

获取数据的模式。

枚举值:

  • SQL:SQL取数方式

  • ROW_KEY:ROW_KEY取数方式 仅适用于HBASE

  • PREFIX_FILTER:PREFIX_FILTER取数方式仅适用于HBASE

access_type

String

取数方式(已弃用)。

枚举值:

  • SCRIPT:脚本方式

  • CONFIGURAITON:配置方式

pagination

String

分页方式。

枚举值:

  • DEFAULT:默认分页

  • CUSTOM:自定义分页

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。

表6 RequestPara

参数

是否必选

参数类型

描述

name

String

参数名。

position

String

参数的位置。

枚举值:

  • REQUEST_PARAMETER_POSITION_PATH:请求PATH内参数

  • REQUEST_PARAMETER_POSITION_HEADER:请求HEADER内参数

  • REQUEST_PARAMETER_POSITION_QUERY:请求QUERY参数

type

String

常量参数类型。

枚举值:

  • REQUEST_PARAMETER_TYPE_NUMBER:数值类型

  • REQUEST_PARAMETER_TYPE_STRING:字符串类型

description

String

参数的描述。

necessary

Boolean

参数是否必填。

example_value

String

示例值。

default_value

String

默认值。

support_null

Boolean

支持NULL值。

表7 ApiRequestPara

参数

是否必选

参数类型

描述

name

String

参数名称。

mapping

String

映射字段。

condition

String

操作符。

枚举值:

  • CONDITION_TYPE_EQ:等于

  • CONDITION_TYPE_NE:不等于

  • CONDITION_TYPE_GT:大于

  • CONDITION_TYPE_GE:大于等于

  • CONDITION_TYPE_LT:小于

  • CONDITION_TYPE_LE:小于等于

  • CONDITION_TYPE_LIKE:模糊查询如:%like%

  • CONDITION_TYPE_LIKE_L:模糊查询如:%like

  • CONDITION_TYPE_LIKE_R:模糊查询如:like%

表8 ApiResponsePara

参数

是否必选

参数类型

描述

name

String

参数名。

field

String

绑定的表字段。

type

String

常量参数类型。

枚举值:

  • REQUEST_PARAMETER_TYPE_NUMBER:数值类型

  • REQUEST_PARAMETER_TYPE_STRING:字符串类型

description

String

参数描述。

example_value

String

参数示例值。

表9 DatasourceOrderPara

参数

是否必选

参数类型

描述

name

String

排序参数名称。

field

String

对应的参数字段。

optional

Boolean

是否可选。

sort

String

排序方式。

枚举值:

  • ASC: 升序

  • DESC: 降序

  • CUSTOM: 自定义

order

Integer

排序参数顺序。

description

String

排序参数描述信息。

表10 BackendConfig

参数

是否必选

参数类型

描述

type

String

请求类型。

  • REQUEST_TYPE_POST:POST请求

  • REQUEST_TYPE_GET:GET请求

protocol

String

API请求协议类型。

  • PROTOCOL_TYPE_HTTP:HTTP协议请求

  • PROTOCOL_TYPE_HTTPS:HTTPS协议请求

host

String

后端HOST。

timeout

Integer

后端超时时间。

path

String

后端请求PATH。

backend_paras

Array of BackendRequestPara objects

API后端参数。

constant_paras

Array of BackendConstant objects

后端常量参数。

表11 BackendRequestPara

参数

是否必选

参数类型

描述

name

String

API请求参数名称。

position

String

参数的位置。

枚举值:

  • REQUEST_PARAMETER_POSITION_PATH:请求PATH内参数

  • REQUEST_PARAMETER_POSITION_HEADER:请求HEADER内参数

  • REQUEST_PARAMETER_POSITION_QUERY:请求QUERY参数

backend_para_name

String

对应的后端参数。

表12 BackendConstant

参数

是否必选

参数类型

描述

name

String

常量参数名。

type

String

常量参数类型。

枚举值:

  • REQUEST_PARAMETER_TYPE_NUMBER:数值类型

  • REQUEST_PARAMETER_TYPE_STRING:字符串类型

position

String

参数的位置。

枚举值:

  • REQUEST_PARAMETER_POSITION_PATH:请求PATH内参数

  • REQUEST_PARAMETER_POSITION_HEADER:请求HEADER内参数

  • REQUEST_PARAMETER_POSITION_QUERY:请求QUERY参数

description

String

常量参数描述。

value

String

常量参数值。

响应参数

状态码: 200

表13 响应Body参数

参数

参数类型

描述

id

String

创建成功的API ID。

状态码: 400

表14 响应Body参数

参数

参数类型

描述

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。