你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Product Policy - Create Or Update
创建或更新产品的策略配置。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/policies/policy?api-version=2022-08-01
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
policy
|
path | True |
策略的标识符。 |
|
product
|
path | True |
string |
产品标识符。 在当前API 管理服务实例中必须是唯一的。 |
resource
|
path | True |
string |
资源组的名称。 此名称不区分大小写。 |
service
|
path | True |
string |
API 管理服务的名称。 Regex pattern: |
subscription
|
path | True |
string |
目标订阅的 ID。 |
api-version
|
query | True |
string |
要用于此操作的 API 版本。 |
请求头
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
If-Match |
string |
实体的 ETag。 创建实体时不需要,但在更新实体时是必需的。 |
请求正文
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
properties.value | True |
string |
格式定义的策略的内容。 |
properties.format |
policyContent 的格式。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
已成功更新租户的产品策略配置。 Headers ETag: string |
|
201 Created |
已成功创建产品策略配置。 Headers ETag: string |
|
Other Status Codes |
描述操作失败原因的错误响应。 |
安全性
azure_auth
Azure Active Directory OAuth2 流。
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
名称 | 说明 |
---|---|
user_impersonation | 模拟用户帐户 |
示例
ApiManagementCreateProductPolicy
Sample Request
PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/products/5702e97e5157a50f48dce801/policies/policy?api-version=2022-08-01
{
"properties": {
"format": "xml",
"value": "<policies>\r\n <inbound>\r\n <rate-limit calls=\"{{call-count}}\" renewal-period=\"15\"></rate-limit>\r\n <log-to-eventhub logger-id=\"16\">\r\n @( string.Join(\",\", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name) ) \r\n </log-to-eventhub>\r\n <quota-by-key calls=\"40\" counter-key=\"cc\" renewal-period=\"3600\" increment-count=\"@(context.Request.Method == "POST" ? 1:2)\" />\r\n <base />\r\n </inbound>\r\n <backend>\r\n <base />\r\n </backend>\r\n <outbound>\r\n <base />\r\n </outbound>\r\n</policies>"
}
}
Sample Response
{
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/products/5702e97e5157a50f48dce801/policies/policy",
"type": "Microsoft.ApiManagement/service/products/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound>\r\n <rate-limit calls=\"{{58c884fed8d14f127cec38f0}}\" renewal-period=\"15\" version=\"2\"></rate-limit>\r\n <log-to-eventhub logger-id=\"16\">\r\n @( string.Join(\",\", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name) ) \r\n </log-to-eventhub>\r\n <quota-by-key calls=\"40\" counter-key=\"cc\" renewal-period=\"3600\" increment-count=\"@(context.Request.Method == "POST" ? 1:2)\" />\r\n <base />\r\n </inbound>\r\n <backend>\r\n <base />\r\n </backend>\r\n <outbound>\r\n <base />\r\n </outbound>\r\n</policies>"
}
}
{
"id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/products/5702e97e5157a50f48dce801/policies/policy",
"type": "Microsoft.ApiManagement/service/products/policies",
"name": "policy",
"properties": {
"value": "<policies>\r\n <inbound>\r\n <rate-limit calls=\"{{58c884fed8d14f127cec38f0}}\" renewal-period=\"15\" version=\"2\"></rate-limit>\r\n <log-to-eventhub logger-id=\"16\">\r\n @( string.Join(\",\", DateTime.UtcNow, context.Deployment.ServiceName, context.RequestId, context.Request.IpAddress, context.Operation.Name) ) \r\n </log-to-eventhub>\r\n <quota-by-key calls=\"40\" counter-key=\"cc\" renewal-period=\"3600\" increment-count=\"@(context.Request.Method == "POST" ? 1:2)\" />\r\n <base />\r\n </inbound>\r\n <backend>\r\n <base />\r\n </backend>\r\n <outbound>\r\n <base />\r\n </outbound>\r\n</policies>"
}
}
定义
名称 | 说明 |
---|---|
Error |
错误字段协定。 |
Error |
错误响应。 |
Policy |
policyContent 的格式。 |
Policy |
策略协定详细信息。 |
Policy |
策略的标识符。 |
ErrorFieldContract
错误字段协定。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
属性级错误代码。 |
message |
string |
属性级错误的可读表示形式。 |
target |
string |
属性名称。 |
ErrorResponse
错误响应。
名称 | 类型 | 说明 |
---|---|---|
error.code |
string |
服务定义的错误代码。 此代码用作响应中指定的 HTTP 错误代码的子状态。 |
error.details |
在发生验证错误时,请求中发送的无效字段列表。 |
|
error.message |
string |
错误的用户可读表示形式。 |
PolicyContentFormat
policyContent 的格式。
名称 | 类型 | 说明 |
---|---|---|
rawxml |
string |
内容是内联的,内容类型是非 XML 编码的策略文档。 |
rawxml-link |
string |
策略文档不是 XML 编码的,托管在可从API 管理服务访问的 HTTP 终结点上。 |
xml |
string |
内容是内联的,内容类型是 XML 文档。 |
xml-link |
string |
策略 XML 文档托管在可从 API 管理 服务访问的 HTTP 终结点上。 |
PolicyContract
策略协定详细信息。
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
id |
string |
资源的完全限定的资源 ID。 例如 - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} |
|
name |
string |
资源的名称 |
|
properties.format | xml |
policyContent 的格式。 |
|
properties.value |
string |
格式定义的策略的内容。 |
|
type |
string |
资源类型。 例如“Microsoft.Compute/virtualMachines”或“Microsoft.Storage/storageAccounts” |
PolicyIdName
策略的标识符。
名称 | 类型 | 说明 |
---|---|---|
policy |
string |