商店 API 函数
借助这些 API 函数,您可以管理宠物店的库存和订单。
获取宠物库存
按状态返回宠物库存。
接口:https://petstore3.swagger.io/api/v3/store/inventory
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/store/inventory" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/store/inventory" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 状态码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 默认 | 意外错误 |
响应示例
200: Successful operation
{
"sold": 0,
"available": 0,
"pending": 0
}
参数
无
下单
为宠物下单。
接口:https://petstore3.swagger.io/api/v3/store/order
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/store/order" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d '{
"id": 0,
"petId": 0,
"quantity": 0,
"shipDate": "2025-08-11T15:13:06.939Z",
"status": "placed",
"complete": false
}'
POST "https://petstore3.swagger.io/api/v3/store/order" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-d '{
"id": 0,
"petId": 0,
"quantity": 0,
"shipDate": "2025-08-11T15:13:06.939Z",
"status": "placed",
"complete": false
}'
响应
| 状态码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 订单无效 |
| default | 意外错误 |
响应示例
200: Successful operation
{
"id": 0,
"petId": 0,
"quantity": 0,
"shipDate": "2025-08-11T15:13:06.939Z",
"status": "placed",
"complete": false
}
参数
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | 订单对象 | (必填) 宠物的 Order 对象。 |
查询订单
根据 ID 查询订单。
接口地址:https://petstore3.swagger.io/api/v3/store/order/{orderId}
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/store/order/1" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/store/order/1" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 状态码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 提供的 ID 无效 |
| 404 | 未找到订单 |
| 默认 | 意外错误 |
响应示例
200: Successful operation
{
"id": 1,
"petId": 0,
"quantity": 0,
"shipDate": "2025-08-11T15:13:06.939Z",
"status": "placed",
"complete": false
}
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| orderId | 整数 | 要获取的采购订单 ID |
删除订单
根据 ID 删除订单。
端点:https://petstore3.swagger.io/api/v3/store/order/{orderId}
操作:DELETE
示例
- API 密钥
- OAuth 2.0
DELETE "https://petstore3.swagger.io/api/v3/store/order/1" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
DELETE "https://petstore3.swagger.io/api/v3/store/order/1" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 订单已删除 |
| 400 | 提供的 ID 无效 |
| 404 | 未找到订单 |
| 默认 | 意外错误 |
(删除成功将返回 200 状态码,且无响应正文。)
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| orderId | 整数 | 要删除的订单 ID |