你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Api Operation - Create Or Update

在 API 中创建新作或更新现有作。

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}?api-version=2024-05-01

URI 参数

名称 必需 类型 说明
apiId
path True

string

minLength: 1
maxLength: 256
pattern: ^[^*#&+:<>?]+$

API 修订标识符。 当前 API 管理服务实例中必须是唯一的。 非当前修订有;rev=n 作为后缀,其中 n 是修订号。

operationId
path True

string

minLength: 1
maxLength: 80

API 中的作标识符。 当前 API 管理服务实例中必须是唯一的。

resourceGroupName
path True

string

minLength: 1
maxLength: 90

资源组的名称。 名称不区分大小写。

serviceName
path True

string

minLength: 1
maxLength: 50
pattern: ^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$

API 管理服务的名称。

subscriptionId
path True

string (uuid)

目标订阅的 ID。 该值必须是 UUID。

api-version
query True

string

minLength: 1

用于此作的 API 版本。

请求头

名称 必需 类型 说明
If-Match

string

实体的 ETag。 创建实体时不需要,但在更新实体时是必需的。

请求正文

名称 必需 类型 说明
properties.displayName True

string

minLength: 1
maxLength: 300

作名称。

properties.method True

string

有效的 HTTP作方法。 典型的 Http 方法,如 GET、PUT、POST,但不仅限于它们。

properties.urlTemplate True

string

minLength: 1
maxLength: 1000

标识此作的目标资源的相对 URL 模板。 可能包括参数。 示例:/customers/{cid}/orders/{oid}/?date={date}

properties.description

string

maxLength: 1000

作的说明。 可能包括 HTML 格式标记。

properties.policies

string

作策略

properties.request

RequestContract

包含请求详细信息的实体。

properties.responses

ResponseContract[]

作响应数组。

properties.templateParameters

ParameterContract[]

URL 模板参数的集合。

响应

名称 类型 说明
200 OK

OperationContract

作已成功更新。

标头

ETag: string

201 Created

OperationContract

已成功创建作。

标头

ETag: string

Other Status Codes

ErrorResponse

描述作失败的原因的错误响应。

安全性

azure_auth

Azure Active Directory OAuth2 Flow。

类型: oauth2
流向: implicit
授权 URL: https://login.microsoftonline.com/common/oauth2/authorize

作用域

名称 说明
user_impersonation 模拟用户帐户

示例

ApiManagementCreateApiOperation

示例请求

PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/PetStoreTemplate2/operations/newoperations?api-version=2024-05-01

{
  "properties": {
    "displayName": "createUser2",
    "method": "POST",
    "urlTemplate": "/user1",
    "templateParameters": [],
    "description": "This can only be done by the logged in user.",
    "request": {
      "description": "Created user object",
      "queryParameters": [],
      "headers": [],
      "representations": [
        {
          "contentType": "application/json",
          "schemaId": "592f6c1d0af5840ca8897f0c",
          "typeName": "User"
        }
      ]
    },
    "responses": [
      {
        "statusCode": 200,
        "description": "successful operation",
        "representations": [
          {
            "contentType": "application/xml"
          },
          {
            "contentType": "application/json"
          }
        ],
        "headers": []
      }
    ]
  }
}

示例响应

{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/PetStoreTemplate2/operations/newoperations",
  "type": "Microsoft.ApiManagement/service/apis/operations",
  "name": "newoperations",
  "properties": {
    "displayName": "createUser2",
    "method": "POST",
    "urlTemplate": "/user1",
    "templateParameters": [],
    "description": "This can only be done by the logged in user.",
    "request": {
      "description": "Created user object",
      "queryParameters": [],
      "headers": [],
      "representations": [
        {
          "contentType": "application/json",
          "schemaId": "592f6c1d0af5840ca8897f0c",
          "typeName": "User"
        }
      ]
    },
    "responses": [
      {
        "statusCode": 200,
        "description": "successful operation",
        "representations": [
          {
            "contentType": "application/xml"
          },
          {
            "contentType": "application/json"
          }
        ],
        "headers": []
      }
    ]
  }
}
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/PetStoreTemplate2/operations/newoperations",
  "type": "Microsoft.ApiManagement/service/apis/operations",
  "name": "newoperations",
  "properties": {
    "displayName": "createUser2",
    "method": "POST",
    "urlTemplate": "/user1",
    "templateParameters": [],
    "description": "This can only be done by the logged in user.",
    "request": {
      "description": "Created user object",
      "queryParameters": [],
      "headers": [],
      "representations": [
        {
          "contentType": "application/json",
          "schemaId": "592f6c1d0af5840ca8897f0c",
          "typeName": "User"
        }
      ]
    },
    "responses": [
      {
        "statusCode": 200,
        "description": "successful operation",
        "representations": [
          {
            "contentType": "application/xml"
          },
          {
            "contentType": "application/json"
          }
        ],
        "headers": []
      }
    ]
  }
}

定义

名称 说明
ErrorAdditionalInfo

资源管理错误附加信息。

ErrorDetail

错误详细信息。

ErrorResponse

错误响应

OperationContract

API作详细信息。

ParameterContract

作参数详细信息。

ParameterExampleContract

参数示例。

RepresentationContract

作请求/响应表示形式详细信息。

RequestContract

作请求详细信息。

ResponseContract

作响应详细信息。

ErrorAdditionalInfo

资源管理错误附加信息。

名称 类型 说明
info

object

其他信息。

type

string

其他信息类型。

ErrorDetail

错误详细信息。

名称 类型 说明
additionalInfo

ErrorAdditionalInfo[]

错误附加信息。

code

string

错误代码。

details

ErrorDetail[]

错误详细信息。

message

string

错误消息。

target

string

错误目标。

ErrorResponse

错误响应

名称 类型 说明
error

ErrorDetail

错误对象。

OperationContract

API作详细信息。

名称 类型 说明
id

string

资源的完全限定资源 ID。 Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}

name

string

资源的名称

properties.description

string

maxLength: 1000

作的说明。 可能包括 HTML 格式标记。

properties.displayName

string

minLength: 1
maxLength: 300

作名称。

properties.method

string

有效的 HTTP作方法。 典型的 Http 方法,如 GET、PUT、POST,但不仅限于它们。

properties.policies

string

作策略

properties.request

RequestContract

包含请求详细信息的实体。

properties.responses

ResponseContract[]

作响应数组。

properties.templateParameters

ParameterContract[]

URL 模板参数的集合。

properties.urlTemplate

string

minLength: 1
maxLength: 1000

标识此作的目标资源的相对 URL 模板。 可能包括参数。 示例:/customers/{cid}/orders/{oid}/?date={date}

type

string

资源的类型。 例如“Microsoft.Compute/virtualMachines”或“Microsoft.Storage/storageAccounts”

ParameterContract

作参数详细信息。

名称 类型 说明
defaultValue

string

默认参数值。

description

string

参数说明。

examples

<string,  ParameterExampleContract>

为参数定义的示例。

name

string

参数名称。

required

boolean

指定参数是否是必需的。

schemaId

string

架构标识符。

type

string

参数类型。

typeName

string

由架构定义的类型名称。

values

string[]

参数值。

ParameterExampleContract

参数示例。

名称 类型 说明
description

string

示例的长说明

externalValue

string

指向文本示例的 URL

summary

string

示例的简短说明

value

示例值。 可以是基元值或对象。

RepresentationContract

作请求/响应表示形式详细信息。

名称 类型 说明
contentType

string

为此表示形式指定已注册或自定义内容类型,例如 application/xml。

examples

<string,  ParameterExampleContract>

为表示形式定义的示例。

formParameters

ParameterContract[]

表单参数的集合。 如果“contentType”值为“application/x-www-form-urlencoded”或“multipart/form-data”,则是必需的。

schemaId

string

架构标识符。 仅当“contentType”值既不是“application/x-www-form-urlencoded”也不是“multipart/form-data”时适用。

typeName

string

由架构定义的类型名称。 仅当“contentType”值既不是“application/x-www-form-urlencoded”也不是“multipart/form-data”时适用。

RequestContract

作请求详细信息。

名称 类型 说明
description

string

作请求说明。

headers

ParameterContract[]

作请求标头的集合。

queryParameters

ParameterContract[]

作请求查询参数的集合。

representations

RepresentationContract[]

作请求表示形式的集合。

ResponseContract

作响应详细信息。

名称 类型 说明
description

string

作响应说明。

headers

ParameterContract[]

作响应标头的集合。

representations

RepresentationContract[]

作响应表示形式的集合。

statusCode

integer (int32)

作响应 HTTP 状态代码。