edit-icon download-icon

Create an API

Last Updated: Jan 22, 2018

Description

For creating an API.

  • The API is intended for users who need to open an API.
  • Duplicate API names in the same group are not allowed.
  • Duplicate paths in the same group are not allowed.
  • A group can contain up to 1000 APIs.
  • This API can call up to 50 QPS for a single user.

Request parameters

Name Type Required? Description
Action String Yes Operation interface, which is a required parameter; value: CreateApi.
GroupId String Yes ID of the specified group.
ApiName String Yes Name of the API, which is unique in the group. Names must be a string of 4–50 characters, which can contain Chinese characters, English letters, numbers, and underscores, and starts with an English letter or Chinese character.
Visibility String Yes Indicates whether the API is public; values:
  • PUBLIC: If the type is set to public, this API’s launch stage will be shown on the Discover APIs page of the console for all users.
  • PRIVATE: When an API group is available on the Cloud Marketplace, private APIs are unavailable.
Description String Yes Description on the API, at most 180 characters.
AuthType String Yes API security authorization type; values:
  • App: Only authorized apps can call the API.
  • ANONYMOUS: The API can be called anonymously. In such a mode, you must note that:
    • Anyone who can obtain this API service information can call this API. The gateway does not authenticate the identity of callers and cannot set traffic limits for individual users. If you activate this API, set API-based throttling.
    • ANONYMOUS API is not recommended to be made available on the Cloud Marketplace. The gateway cannot meter callers separately and cannot control the number of calls. If the group including this API is to be added to the Cloud Marketplace, it is suggested to move this API to another group, or set its type to private, or select the Alibaba Cloud App certification method.
RequestConfig String Yes Configuration items of the API request sent by a consumer to the gateway.
ServiceConfig String Yes Configuration items of the API request sent by the gateway to a backend service.
RequestParameters String Yes Description on parameters of the API request sent by a consumer to the gateway.
ServiceParameters String Yes Description on parameters of the API request sent by the gateway to a backend service.
ServiceParametersMap String Yes The mappings between parameters of a request sent by a consumer to the gateway and parameters of a request sent by the gateway to a backend service.
ResultType String Yes Format of the reply returned by the backend service. Currently, allowed formats are JSON, TEXT, BINARY, XML, and HTML.
ResultSample String Yes Sample of the reply returned by the backend service.
FailResultSample String No Sample of the reply failure returned by the backend service.
ErrorCodeSamples String No Sample of the error code returned by the backend service.

Return parameters

Name Type Description
RequestId String ID of the current API creation request.
ApiId String ID of the currently created API.

Examples

Request example

  1. https://apigateway.cn-qingdao.aliyuncs.com/?Action=CreateApi
  2. &GroupId=08ae4aa0f95e4321849ee57f4e0b3077
  3. &ApiName=ApiName
  4. &Visibility=PUBLIC
  5. &Description=Api description
  6. &AuthType=APP
  7. &RequestConfig={"RequestProtocol":"HTTP","RequestHttpMethod":"GET","RequestPath":"/v3/getUserTest/[userId]","BodyFormat":"FORM","PostBodyDescription":""}
  8. &ServiceConfig={"ServiceProtocol":"HTTP","ServiceHttpMethod":"GET","ServiceAddress":"http://www.customerdomain.com","ServiceTimeout":"1000","ServicePath":"/v3/getUserTest/[userId]"}
  9. &RequestParamters=[{"ParameterType":"Number","Required":"OPTIONAL","isHide":false,"ApiParameterName":"age","DefaultValue":"20","DemoValue":"20","Description":"Age","MinValue":18,"MaxValue":100,"Location":"Head"},{"ParameterType":"String","Required":"OPTIONAL","isHide":false,"ApiParameterName":"sex","DefaultValue":"boy","DemoValue":"boy","Description":"Gender","EnumValue":"boy,girl","Location":"Query"},{"ParameterType":"Number","Required":"REQUIRED","isHide":false,"ApiParameterName":"userId","MaxLength":10,"MinValue":10000000,"MaxValue":100000000,"Location":"Path"},{"ApiParameterName":"CaClientIp","ParameterLocation":{"name":"Head","orderNumber":0},"Location":"Head","ParameterType":"String","Required":"REQUIRED","Description":"Client IP address"},{"ApiParameterName":"constance","ParameterLocation":{"name":"Head","orderNumber":0},"Location":"Head","ParameterType":"String","Required":"REQUIRED","DefaultValue":"constance","Description":"constance"}]
  10. &ServiceParameters=[{"ServiceParameterName":"age","Location":"Head","Type":"Number","ParameterCatalog":"REQUEST"},{"ServiceParameterName":"sex","Location":"Query","Type":"String","ParameterCatalog":"REQUEST"},{"ServiceParameterName":"userId","Location":"Path","Type":"Number","ParameterCatalog":"REQUEST"},{"ServiceParameterName":"clientIp","Location":"Head","Type":"String","ParameterCatalog":"SYSTEM"},{"ServiceParameterName":"constance","Location":"Head","Type":"String","ParameterCatalog":"CONSTANT"}]
  11. &ServiceParametersMap=[{"ServiceParameterName":"age","RequestParameterName":"age"},{"ServiceParameterName":"sex","RequestParameterName":"sex"},{"ServiceParameterName":"userId","RequestParameterName":"userId"},{"ServiceParameterName":"clientIp","RequestParameterName":"CaClientIp"},{"ServiceParameterName":"constance","RequestParameterName":"constance"}]
  12. &ResultType=HTML
  13. &ResultSample=200
  14. &<Public request parameters>

Response example

XML format

  1. <CreateApiResponse>
  2. <RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
  3. <ApiId>8afff6c8c4c6447abb035812e4d66b65</ApiId>
  4. </CreateApiResponse>

JSON format

  1. {
  2. "RequestId":"6C87A26A-6A18-4B8E-8099-705278381A2C",
  3. "ApiId":"8afff6c8c4c6447abb035812e4d66b65"
  4. }
Thank you! We've received your feedback.