Get SDK code sample
Operation description
This API retrieves public information that is not associated with any specific account and therefore requires no authorization.
Try it now
Test
RAM authorization
Request syntax
POST /api/product/makeCode HTTP/1.1
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| body |
object |
No |
The request body used to generate a code sample. |
|
| callType |
string |
No |
The SDK call type. Valid values: |
typed |
| product |
string |
Yes |
Specifies the product code. |
Ecs |
| apiVersion |
string |
No |
Specifies the OpenAPI version. |
2014-05-26 |
| apiName |
string |
Yes |
Specifies the OpenAPI name. |
DescribeInstances |
| regionId |
string |
No |
Specifies the region ID. |
cn-hangzhou |
| language |
string |
Yes |
Specifies the programming language for the code sample. |
java |
| params |
string |
No |
Specifies the service request parameters for the OpenAPI call, formatted as a JSON string. In this string, keys are parameter names and values are their corresponding serialized values. |
{"RegionId":"cn-hangzhou"} |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
|||
| code |
integer |
The business status code. A value of |
0 |
| message |
string |
The business error message. This field is returned only when |
SDK 示例生成出错,请联系支持群开发同学解决 |
| data |
object |
The generated multilingual SDK code sample and dependency information. |
{} |
| demoSdk |
string |
The SDK code sample. |
package com.aliyun.sample;\n\nimport com.aliyun.tea.*;\n\npublic class Sample {\n\n /**\n * description :\n * 使用凭据初始化账号Client \n * @return Client\n * \n * @throws Exception\n */\n public static com.aliyun.teaopenapi.Client createClient() throws Exception {\n // 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378657.html。\n com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();\n com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()\n .setCredential(credential);\n // Endpoint 请参考 https://api.aliyun.com/product/Ecs\n config.endpoint = \"ecs.us-west-1.aliyuncs.com\";\n return new com.aliyun.teaopenapi.Client(config);\n }\n\n /**\n * description :\n *API 相关 \n * \n * @param path string Path parameters\n * @return OpenApi.Params\n */\n public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {\n com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()\n // 接口名称\n .setAction(\"DescribeInstances\")\n // 接口版本\n .setVersion(\"2014-05-26\")\n // 接口协议\n .setProtocol(\"HTTPS\")\n // 接口 HTTP 方法\n .setMethod(\"POST\")\n .setAuthType(\"AK\")\n .setStyle(\"RPC\")\n // 接口 PATH\n .setPathname(\"/\")\n // 接口请求体内容格式\n .setReqBodyType(\"json\")\n // 接口响应体内容格式\n .setBodyType(\"json\");\n return params;\n }\n\n public static void main(String[] args_) throws Exception {\n \n com.aliyun.teaopenapi.Client client = Sample.createClient();\n com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo();\n // query params\n java.util.Map |
| cost |
integer |
The generation time, in milliseconds. |
100 |
| sdkDependency |
object |
The SDK installation information that corresponds to the specified cloud product, API version, programming language, and invocation method. The object structure matches a single result from the |
{"packageName":"com.aliyun/openapiexplorer20241130","sdkVersion":"1.3.0","platform":"maven","install":" |
| packageName |
string |
The SDK package name. |
com.aliyun/openapiexplorer20241130 |
| sdkVersion |
string |
The SDK package version. |
1.3.0 |
| platform |
string |
The SDK package management platform, such as GitHub, Maven, PyPI, NuGet, or npm. |
maven |
| install |
string |
The SDK installation instructions. For Java, this is the Maven |
|
Examples
Success response
JSON format
{
"code": 0,
"message": "SDK 示例生成出错,请联系支持群开发同学解决",
"data": {
"demoSdk": "package com.aliyun.sample;\\n\\nimport com.aliyun.tea.*;\\n\\npublic class Sample {\\n\\n /**\\n * description :\\n *
使用凭据初始化账号Client\\n * @return Client\\n * \\n * @throws Exception\\n */\\n public static com.aliyun.teaopenapi.Client createClient() throws Exception {\\n // 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378657.html。\\n com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();\\n com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()\\n .setCredential(credential);\\n // Endpoint 请参考 https://api.aliyun.com/product/Ecs\\n config.endpoint = \\\"ecs.us-west-1.aliyuncs.com\\\";\\n return new com.aliyun.teaopenapi.Client(config);\\n }\\n\\n /**\\n * description :\\n *
API 相关\\n * \\n * @param path string Path parameters\\n * @return OpenApi.Params\\n */\\n public static com.aliyun.teaopenapi.models.Params createApiInfo() throws Exception {\\n com.aliyun.teaopenapi.models.Params params = new com.aliyun.teaopenapi.models.Params()\\n // 接口名称\\n .setAction(\\\"DescribeInstances\\\")\\n // 接口版本\\n .setVersion(\\\"2014-05-26\\\")\\n // 接口协议\\n .setProtocol(\\\"HTTPS\\\")\\n // 接口 HTTP 方法\\n .setMethod(\\\"POST\\\")\\n .setAuthType(\\\"AK\\\")\\n .setStyle(\\\"RPC\\\")\\n // 接口 PATH\\n .setPathname(\\\"/\\\")\\n // 接口请求体内容格式\\n .setReqBodyType(\\\"json\\\")\\n // 接口响应体内容格式\\n .setBodyType(\\\"json\\\");\\n return params;\\n }\\n\\n public static void main(String[] args_) throws Exception {\\n \\n com.aliyun.teaopenapi.Client client = Sample.createClient();\\n com.aliyun.teaopenapi.models.Params params = Sample.createApiInfo();\\n // query params\\n java.util.Map queries = new java.util.HashMap<>();\\n queries.put(\\\"RegionId\\\", \\\"us-west-1\\\");\\n // runtime options\\n com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();\\n com.aliyun.teaopenapi.models.OpenApiRequest request = new com.aliyun.teaopenapi.models.OpenApiRequest()\\n .setQuery(com.aliyun.openapiutil.Client.query(queries));\\n // 返回值实际为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。\\n Object resp = client.callApi(params, request, runtime);\\n System.out.println(new com.google.gson.Gson().toJson(resp));\\n }\\n}\\n",
"cost": 100,
"sdkDependency": {
"packageName": "com.aliyun/openapiexplorer20241130",
"sdkVersion": "1.3.0",
"platform": "maven",
"install": "\\n com.aliyun\\n openapiexplorer20241130\\n 1.3.0\\n"
}
}
}
Error codes
|
HTTP status code |
Error code |
Error message |
Description |
|---|---|---|---|
| 400 | InvalidParam.Body | Request body is required. | |
| 400 | InvalidParam.Product | Product name is required and cannot be null or empty. | |
| 400 | InvalidParam.ApiVersion | API version is required and cannot be null or empty. | |
| 400 | InvalidParam.ApiName | API name is required and cannot be null or empty. | |
| 400 | InvalidParam.Format | Product/apiVersion/apiName format is invalid. | |
| 400 | InvalidParam.Language | Language format is invalid. | |
| 400 | InvalidParam.CallType | CallType must be typed or generic. | |
| 502 | WorkbenchProxy.RequestFailed | Failed to generate code sample. |
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.