OpenAPI元数据

更新时间:

阿里云提供了丰富的API接口,支持用户通过编程方式访问和管理云资源。在使用这些API时,特别是在自签名场景下,正确理解和运用API的元数据对于实现自签名机制至关重要。本文将为您介绍在自签名场景中,如何快速获取自签名所需的信息。

云产品元数据介绍

云产品的OpenAPI元数据是指与API相关的所有描述性信息的集合。在进行签名操作时,您需要从以下参数中获取云产品的API风格,以及API所支持的协议、请求方法、参数名称、参数类型及参数位置等相关信息。

产品及版本的概述信息(Info)

包括产品的API风格、产品Code及其版本。

示例:

{"style":"RPC","product":"Ecs","version":"2014-05-26"}

API概要信息集合(apis)

采用Map结构,其中Key为API名称,值为相应的API概要信息。API概要信息中包含以下参数信息:

参数名称

参数描述

示例

methods

支持的请求方法集合。

["post","get"]

表示API同时支持POST和GET请求方式,但两者在调用结果上无任何差异。

schemes

支持的协议集合。

["http","https" ]

表示API同时支持HTTP协议和HTTPS协议。

parameters

请求参数集合。

{
    "name": "RegionId",
    "in": "query",
    "schema": {
        "description": "实例所属的地域ID。您可以调用[DescribeRegions](~~25609~~)查看最新的阿里云地域列表。",
        "type": "string",
        "required": true,
        "example": "cn-hangzhou"
    }
}

具体描述了参数名称、参数位置(query、path、body)、参数类型以及是否为必传等信息。

DescribeInstanceStatus的元数据

{
    "code": 0,
    "data": {
        "methods": [
            "post",
            "get"
        ],
        "schemes": [
            "http",
            "https"
        ],
        "security": [
            {
                "AK": []
            }
        ],
        "deprecated": false,
        "systemTags": {
            "operationType": "get"
        },
        "parameters": [
            {
                "name": "RegionId",
                "in": "query",
                "schema": {
                    "description": "实例所属的地域ID。您可以调用[DescribeRegions](~~25609~~)查看最新的阿里云地域列表。",
                    "type": "string",
                    "required": true,
                    "example": "cn-hangzhou"
                }
            },
            {
                "name": "ZoneId",
                "in": "query",
                "schema": {
                    "description": "实例所属可用区。您可以调用[DescribeZones](~~25610~~)查看最新的阿里云可用区列表。",
                    "type": "string",
                    "required": false,
                    "example": "cn-hangzhou-d"
                }
            },
            {
                "name": "ClusterId",
                "in": "query",
                "schema": {
                    "description": "实例所属的集群ID。\n\n><notice>该参数已废弃,不建议使用!></notice>",
                    "type": "string",
                    "required": false,
                    "example": "cls-bp67acfmxazb4p****"
                }
            },
            {
                "name": "PageNumber",
                "in": "query",
                "schema": {
                    "description": "实例状态列表的页码。\n\n起始值:1。\n\n默认值:1。",
                    "type": "integer",
                    "format": "int32",
                    "required": false,
                    "minimum": "1",
                    "example": "1",
                    "default": "1"
                }
            },
            {
                "name": "PageSize",
                "in": "query",
                "schema": {
                    "description": "分页查询时设置的每页行数。取值范围:1~50。\n\n默认值:10。",
                    "type": "integer",
                    "format": "int32",
                    "required": false,
                    "maximum": "50",
                    "minimum": "1",
                    "example": "10",
                    "default": "10"
                }
            },
            {
                "name": "InstanceId",
                "in": "query",
                "style": "repeatList",
                "schema": {
                    "description": "实例ID数组。数组长度:1~100。\n\n示例值:[\"i-bp1j4i2jdf3owlhe****\", \"i-bp1j4i2jdf3o1234****\"]。",
                    "type": "array",
                    "items": {
                        "description": "实例ID。",
                        "type": "string",
                        "required": false,
                        "example": "i-bp1j4i2jdf3owlhe****"
                    },
                    "required": false,
                    "example": "i-bp1j4i2jdf3owlhe****",
                    "maxItems": 100
                }
            }
        ],
        "responses": {
            "200": {
                "schema": {
                    "type": "object",
                    "properties": {
                        "PageSize": {
                            "description": "输入时设置的每页行数。",
                            "type": "integer",
                            "format": "int32",
                            "example": "1"
                        },
                        "RequestId": {
                            "description": "请求ID。",
                            "type": "string",
                            "example": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
                        },
                        "PageNumber": {
                            "description": "实例列表的页码。",
                            "type": "integer",
                            "format": "int32",
                            "example": "1"
                        },
                        "TotalCount": {
                            "description": "实例总个数。",
                            "type": "integer",
                            "format": "int32",
                            "example": "58"
                        },
                        "InstanceStatuses": {
                            "type": "object",
                            "itemNode": true,
                            "properties": {
                                "InstanceStatus": {
                                    "description": "实例ID和状态(InstanceStatus)的集合。",
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "Status": {
                                                "description": "实例状态。可能值: \n\n- Pending:创建中。\n\n- Running:运行中。\n\n- Starting:启动中。\n\n- Stopping:停止中。\n\n- Stopped:已停止。",
                                                "type": "string",
                                                "example": "Running"
                                            },
                                            "InstanceId": {
                                                "description": "实例ID。",
                                                "type": "string",
                                                "example": "i-bp1j4i2jdf3owlhe****"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "errorCodes": {
            "403": [
                {
                    "errorCode": "InvalidParameter.TooManyInstanceIds",
                    "errorMessage": "Instance ids cannot be more than 100."
                },
                {
                    "errorCode": "Abs.InvalidInstanceIds.MalFormed",
                    "errorMessage": "The specified instanceIds is not valid."
                }
            ],
            "404": [
                {
                    "errorCode": "InvalidZoneId.NotFound",
                    "errorMessage": "The ZoneId provided does not exist in our records."
                }
            ]
        },
        "responseDemo": "[{\"type\":\"json\",\"example\":\"{\\n  \\\"PageSize\\\": 1,\\n  \\\"RequestId\\\": \\\"473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E\\\",\\n  \\\"PageNumber\\\": 1,\\n  \\\"TotalCount\\\": 58,\\n  \\\"InstanceStatuses\\\": {\\n    \\\"InstanceStatus\\\": [\\n      {\\n        \\\"Status\\\": \\\"Running\\\",\\n        \\\"InstanceId\\\": \\\"i-bp1j4i2jdf3owlhe****\\\"\\n      }\\n    ]\\n  }\\n}\",\"errorExample\":\"{\\n\\\"RequestId\\\": \\\"6EF60BEC-0242-43AF-BB20-270359FB54A7\\\",\\n\\\"TotalCount\\\": 2,\\n\\\"PageNumber\\\": 1,\\n\\\"PageSize\\\": 10,\\n\\\"InstanceStatuses\\\": {\\n    \\\"InstanceStatus\\\": [{\\n        \\\"InstanceId\\\": \\\"i-instance1\\\",\\n            \\\"Status\\\": \\\"Running\\\"\\n        },\\n        {\\n            \\\"InstanceId\\\": \\\"i-ae4r89pp\\\",\\n            \\\"Status\\\": \\\"Stopped\\\"\\n        }]\\n    }\\n}\"},{\"type\":\"xml\",\"example\":\"<DescribeInstanceStatusResponse>\\n    <PageNumber>1</PageNumber>\\n    <InstanceStatuses>\\n        <InstanceStatus>\\n            <Status>Running</Status>\\n            <InstanceId>i-bp1j4i2jdf3owlhe****</InstanceId>\\n        </InstanceStatus>\\n    </InstanceStatuses>\\n    <TotalCount>58</TotalCount>\\n    <PageSize>1</PageSize>\\n    <RequestId>746C3444-9A24-4D7D-B8A8-DCBF7AC8BD66</RequestId>\\n</DescribeInstanceStatusResponse>\",\"errorExample\":\"<DescribeInstanceStatusResponse>\\n    <RequestId>6EF60BEC-0242-43AF-BB20-270359FB54A7</RequestId>\\n    <TotalCount>2</TotalCount>\\n    <PageNumber>1</PageNumber>\\n    <PageSize>10</PageSize>\\n    <InstanceStatuses>\\n        <InstanceStatus>\\n            <InstanceId>i-instance1</InstanceId>\\n                <Status>Running</Status>\\n            </InstanceStatus>\\n            <InstanceStatus>\\n                <InstanceId>i-ae4r89pp</InstanceId>\\n                <Status>Stopped</Status>\\n        </InstanceStatus>\\n    </InstanceStatuses>\\n</DescribeInstanceStatusResponse>\"}]",
        "title": "查询实例的状态信息列表",
        "summary": "本接口主要用于查询一台或多台指定ECS实例的状态信息,同时支持查询指定条件下的实例列表。",
        "description": "ECS实例的生命周期状态请参见[实例状态表](~~25687~~)。 \n\n## 请求示例\n- 根据**指定地域**查询实例以及状态信息,入参示例:\n```\n\"RegionID\": \"cn-hangzhou\"\n```\n\n- 根据**指定地域**下的**某个可用区**查询实例以及状态信息,入参示例:\n```\n\"RegionID\": \"cn-hangzhou\",\n\"ZoneID\": \"cn-hangzhou-a\"\n```\n\n- 根据**指定地域**和**实例ID**查询实例对应状态信息,入参示例:\n```\n\"RegionID\": \"cn-hangzhou\",\n\"InstancesID\": [\"i-bp1f7c1zqp999zvp****\", \"i-bp1dqjv36biueg61****\"]\n```",
        "requestParamsDescription": " ",
        "responseParamsDescription": " ",
        "extraInfo": " "
    }
}

服务接入点集合(endpoints

云产品支持服务地址。

元数据获取方式

方式一:获取云产品元数据。

访问API文档,选择对应的云产品,本文以云服务器ECS为例。单击云服务器ECS名称下方的获取元数据

image

方式二:获取某个API的元数据。

访问API文档,选择对应的云产品,本文以云服务器ECS为例。选择将要调用的API,单击页面右上角获取元数据

image

方式三:调用元数据API获取元数据。

元数据API无需进行鉴权,可在公网环境中自由调用。您可以参考下表内容以获取元数据,有关元数据API的详细信息,请参见元数据使用指南

API描述

API URL

请求方式

查询所有云产品CODE及VERSION

https://api.aliyun.com/meta/v1/products.json?language=EN_US

GET

获取指定产品指定版本的元数据

https://api.aliyun.com/meta/v1/products/{product}/versions/{version}/api-docs.json

GET

获取指定API的元数据

https://api.aliyun.com/meta/v1/products/{product}/versions/{version}/apis/{api_name}/api.json

GET