Create API

Last updated: 2020-02-27 15:52:26

PDF

Interface description

This API (CreateApi) is used to create API. Before creating a API, users need to create a service. Each API has its own service.

Input Parameter

The following request parameter list only lists the API request parameters. For other parameters, please see Common Request Parameters .

Parameter name Required Type Description
ServiceId Yes String The service on which API is located is the only ID.
ApiName No String User-defined API name.
ApiDesc No String User-defined API description.
ApiType No String API type, currently only NORMAL, will add other types of API.
AuthRequired No String Whether you need to sign Verification, TRUE means yes, FALSE means no. The default is TRUE. If you need to open the API, in marketplace, you must select TRUE.
EnableCORS No String Whether it is necessary to enable cross-domain, TRUE means yes, FALSE means not. The default is FALSE.
RequestConfig.path Yes String The front-end path to the API, such as / path.
RequestConfig.method Yes String The front-end request method of API, such as GET.
RequestParameters.n.name No String The name of the front-end parameter of the API.
RequestParameters.n.position No String The position of the front-end parameter of the API. Currently, only PATH, QUERY and HEADER are supported.
RequestParameters.n.type No String The frontend parameter types of API, such as String, Int, etc.
RequestParameters.n.defaultValue No String Default values of frontend parameters for API.
RequestParameters.n.required No Boolean Whether the frontend parameter of API is required. TRUE: means required, and FALSE: means optional.
RequestParameters.n.desc No String Remarks for the front-end parameters of API.
ServiceType Yes String Three back-end service types of API are now supported: HTTP, MOCK, and SCF.
ServiceTimeout Yes Int API's backend service timeout (in seconds).
ServiceConfig.url No String URL, the back-end service of API. This parameter is required if serviceType is HTTP, such as http://api.tencentcs.com/apigw.
ServiceConfig.path No String The backend service path of API, such as / path. This parameter is required if serviceType is HTTP,. The paths of the front and rear ends can be different. The API gateway maps the path.
ServiceConfig.method No String The backend service request method of API, such as GET. This parameter is required if serviceType is HTTP,. The methods of the front and rear ends can be different. The API gateway maps the method.
ServiceConfig.uniqVpcId No String Enter is required when using VPC, which represents the only vpcId.
ServiceConfig.product No String It is used with uniqVpcId. Currently, only clb scenarios are supported. Enter "clb"
ServiceParameters.n.name No String The name of the backend service parameter of the API. This parameter is used only if serviceType is HTTP. The parameter name of the backend service can be different from the frontend parameter name. The API gateway maps the parameter names. However, the values of the back-end parameters are the same as those of the front-end parameters.
ServiceParameters.n.position No String The location of the backend service parameter of the API, such as head. This parameter is used only if serviceType is HTTP. The location name of the back-end service can be different from the location of the front-end parameters. The API gateway maps the location of the parameters.
ServiceParameters.n.relevantRequestParameterName No String The name of the frontend parameter corresponding to the backend service parameter of API. This parameter is used only if serviceType is HTTP.
ServiceParameters.n.relevantRequestParameterPosition No String The location of the frontend parameters corresponding to the backend service parameters of API. This parameter is used only if serviceType is HTTP.
ServiceParameters.n.desc No String Remarks on the backend service parameters of API. This parameter is used only if serviceType is HTTP.
ConstantParameters.n.name No String Constant parameter name. This parameter is used only if serviceType is HTTP. The constant parameter is the parameter configured by the API publisher on the backend, and the front-end caller is not visible.
ConstantParameters.n.desc No String Constant parameter description. This parameter is used only if serviceType is HTTP.
ConstantParameters.n.position No String Constant parameter position. Currently, only header and query are supported. This parameter is used only if serviceType is HTTP.
ConstantParameters.n.defaultValue No String Constant parameter default value. This parameter is used only if serviceType is HTTP.
ServiceMockReturnMessage No String The backend Mock of API returns information. This parameter is required if serviceType is Mock,.
ServiceScfFunctionName No String The name of the backend SCF function of the API. This parameter is required if serviceType is Scf,.
ServiceScfIsIntegratedResponse No String Whether to enable SCF integration response. TRUE: enable, FALSE: disable. This parameter is valid only if the backend is of type SCF. The default is FALSE.
ServiceScfFunctionQualifier No String The SCF version number, which defaults to $LATEST.
ResponseType No String Custom response configuration return type. Only HTML, JSON, TEST, BINARY and XML are supported (this configuration is only used to generate API Documentation prompt callers).
ResponseSuccessExample No String Custom response configuration successful response example (this configuration is only used to generate API Documentation prompt callers).
ResponseFailExample No String Custom response configuration failure response example (this configuration is only used to generate API Documentation prompt callers).
ResponseErrorCodes.n.code No Int Custom response configuration original error code (this configuration is only used to generate API Documentation prompt callers).
ResponseErrorCodes.n.convertedCode No Int Custom response configuration mapping error code (this configuration is only used to generate API Documentation prompt callers).
ResponseErrorCodes.n.needConvert No String Whether the mapping is enabled for custom response configuration (this configuration is only used to generate API Documentation prompt callers).
ResponseErrorCodes.n.msg No String Custom response configuration error message (this configuration is only used to generate API Documentation prompt callers).
ResponseErrorCodes.n.desc No String Custom response configures error code comments (this configuration is only used to generate API Documentation prompt callers).

Output Parameter

Parameter name Type Description
Code Int Common error code, 0 indicates success, other values indicate failure. For more information, please see the error code page Common error code .
CodeDesc String Error code on the business side. If a Success, error is returned on success, the cause of the business error is returned.
Message String Module error message description, related to the interface.
ApiId String API is the only ID.
Path String Path.
Method String Request method.
CreatedTime Timestamp Policy creation time. Expressed according to the ISO8601 standard, and using UTC time. The format is: YYYY-MM-DDThh:mm:ssZ.

Example

Create a API whose backend service is HTTP
An example of a request is as follows:

https://apigateway.api.qcloud.com/v2/index.php?
&<Common request parameters>
&Action=CreateApi
&serviceId=service-XX
&apiDesc=myTestApi
&requestConfig.path=/path
&requestConfig.method=GET
&requestParameters.0.name=age
&requestParameters.0.position=HEADER
&requestParameters.0.type=Int
&requestParameters.0.defaultValue=18
&requestParameters.0.required=REQUIRED
&requestParameters.0.description=age
&serviceType=Http
&serviceTimeout=60
&serviceConfig.url=cloud.tencent.com
&serviceConfig.path=/path
&serviceConfig.method=GET
&serviceParameters.0.name=age
&serviceParameters.0.in=HEADER
&serviceParameters.0.relevantRequestParameterName=age
&serviceParameters.0.relevantRequestParameterIn=HEADER
&serviceParameters.0.defaultValue=18
&serviceParameters.0.desc=age
&constantParameters.0.name=aa
&constantParameters.0.desc=aa
&constantParameters.0.position=HEADER
&constantParameters.0.defaultValue=aa

The returned results are as below:

{
    "code": "0",
    "message": "",
    "codeDesc": "Success",
    "apiId": "api-XX",
    "path": "/path",
    "method": "GET",
    "createdTime": "2017-08-07T00:00:00Z"
}

Create a API whose backend service is MOCK
An example of a request is as follows:

https://apigateway.api.qcloud.com/v2/index.php?
&<Common request parameters>
&Action=CreateApi
&serviceId=service-XX
&apiDescription=myTestApi
&requestConfig.path=/path
&requestConfig.method=GET
&requestConfig.protocol=Http
&requestParameters.0.name=age
&requestParameters.0.in=HEADER
&requestParameters.0.type=Int
&requestParameters.0.defaultValue=18
&requestParameters.0.required=REQUIRED
&requestParameters.0.desc=age
&serviceType=MOCK
&serviceTimeout=60
&serviceMockReturnMessage=Returned message from MOCK

The returned results are as below:

{
    "code": "0",
    "message": "",
    "codeDesc": "Success",
    "apiId": "api-XXX",
    "path": "/path",
    "method": "GET",
    "createdTime": "2017-08-07T00:00:00Z"
}

Create a API whose backend service is SCF
An example of a request is as follows:

https://apigateway.api.qcloud.com/v2/index.php?
&<Common request parameters>
&Action=CreateApi
&serviceId=service-XX
&apiDescription=myTestApi
&requestConfig.path=/path
&requestConfig.method=GET
&requestConfig.protocol=Http
&requestParameters.0.name=age
&requestParameters.0.in=HEADER
&requestParameters.0.type=Int
&requestParameters.0.defaultValue=18
&requestParameters.0.required=REQUIRED
&requestParameters.0.description=age
&serviceType=SCF
&serviceTimeout=60
&serviceScfFunctionName=myScfFunction

The returned results are as below:

{
    "code": "0",
    "message": "",
    "codeDesc": "Success",
    "apiId": "api-XXXX",
    "path": "/path",
    "method": "GET",
    "createdTime": "2017-08-07T00:00:00Z"
}