共用方式為


Api Policy - Create Or Update

建立或更新 API 的原則設定。

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/policies/policy?api-version=2021-08-01

URI 參數

名稱 位於 必要 類型 Description
apiId
path True

string

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

API 修訂標識碼。 目前 API 管理服務實例中必須是唯一的。 非目前的修訂具有 ;rev=n 作為後綴,其中 n 是修訂編號。

policyId
path True

PolicyIdName

原則的標識碼。

resourceGroupName
path True

string

資源群組的名稱。

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

可唯一識別Microsoft Azure 訂用帳戶的訂用帳戶認證。 訂用帳戶標識碼會形成每個服務呼叫 URI 的一部分。

api-version
query True

string

要與用戶端要求搭配使用的 API 版本。

要求標頭

名稱 必要 類型 Description
If-Match

string

實體的 ETag。 建立實體時不需要,但在更新實體時則為必要專案。

要求本文

名稱 必要 類型 Description
properties.value True

string

原則的內容,如格式所定義。

properties.format

PolicyContentFormat

policyContent 的格式。

回應

名稱 類型 Description
200 OK

PolicyContract

已成功更新租使用者的 API 原則設定。

標題

ETag: string

201 Created

PolicyContract

已成功建立 API 原則設定。

標題

ETag: string

Other Status Codes

ErrorResponse

描述作業失敗原因的錯誤回應。

安全性

azure_auth

Azure Active Directory OAuth2 Flow。

類型: oauth2
Flow: implicit
授權 URL: https://login.microsoftonline.com/common/oauth2/authorize

範圍

名稱 Description
user_impersonation 模擬您的用戶帳戶

範例

ApiManagementCreateApiPolicy
ApiManagementCreateApiPolicyNonXmlEncoded

ApiManagementCreateApiPolicy

範例要求

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy?api-version=2021-08-01


{
  "properties": {
    "format": "xml",
    "value": "<policies> <inbound /> <backend>    <forward-request />  </backend>  <outbound /></policies>"
  }
}

範例回覆

{
  "id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy",
  "type": "Microsoft.ApiManagement/service/apis/policies",
  "name": "policy",
  "properties": {
    "value": "<policies>\r\n  <inbound />\r\n  <backend>\r\n    <forward-request />\r\n  </backend>\r\n  <outbound />\r\n</policies>"
  }
}
{
  "id": "/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy",
  "type": "Microsoft.ApiManagement/service/apis/policies",
  "name": "policy",
  "properties": {
    "value": "<policies>\r\n  <inbound />\r\n  <backend>\r\n    <forward-request />\r\n  </backend>\r\n  <outbound />\r\n</policies>"
  }
}

ApiManagementCreateApiPolicyNonXmlEncoded

範例要求

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy?api-version=2021-08-01


{
  "properties": {
    "value": "<policies>\r\n     <inbound>\r\n     <base />\r\n  <set-header name=\"newvalue\" exists-action=\"override\">\r\n   <value>\"@(context.Request.Headers.FirstOrDefault(h => h.Ke==\"Via\"))\" </value>\r\n    </set-header>\r\n  </inbound>\r\n      </policies>",
    "format": "rawxml"
  }
}

範例回覆

{
  "id": "/subscriptions/4c1a3bc6-89f9-46fe-a175-5d8984b25095/resourcegroups/Api-DF-West-US/providers/Microsoft.ApiManagement/service/samirmsiservice2/apis/echo-api/operations/create-resource/policies/policy",
  "type": "Microsoft.ApiManagement/service/apis/operations/policies",
  "name": "policy",
  "properties": {
    "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-header name=\"newvalue\" exists-action=\"override\">\r\n      <value>\"@(context.Request.Headers.FirstOrDefault(h =&gt; h.Ke==\"Via\"))\" </value>\r\n    </set-header>\r\n  </inbound>\r\n</policies>"
  }
}
{
  "id": "/subscriptions/4c1a3bc6-89f9-46fe-a175-5d8984b25095/resourcegroups/Api-DF-West-US/providers/Microsoft.ApiManagement/service/samirmsiservice2/apis/echo-api/operations/create-resource/policies/policy",
  "type": "Microsoft.ApiManagement/service/apis/operations/policies",
  "name": "policy",
  "properties": {
    "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-header name=\"newvalue\" exists-action=\"override\">\r\n      <value>\"@(context.Request.Headers.FirstOrDefault(h =&gt; h.Ke==\"Via\"))\" </value>\r\n    </set-header>\r\n  </inbound>\r\n</policies>"
  }
}

定義

名稱 Description
ErrorFieldContract

錯誤欄位合約。

ErrorResponse

錯誤回應。

PolicyContentFormat

policyContent 的格式。

PolicyContract

原則合約詳細數據。

PolicyIdName

原則的標識碼。

ErrorFieldContract

錯誤欄位合約。

名稱 類型 Description
code

string

屬性層級錯誤碼。

message

string

人類可讀取的屬性層級錯誤表示法。

target

string

屬性名稱。

ErrorResponse

錯誤回應。

名稱 類型 Description
error.code

string

服務定義的錯誤碼。 此程式代碼可作為回應中所指定 HTTP 錯誤碼的子狀態。

error.details

ErrorFieldContract[]

要求中傳送無效欄位的清單,以防驗證錯誤。

error.message

string

人類可讀取的錯誤表示法。

PolicyContentFormat

policyContent 的格式。

Description
rawxml

內容是內嵌的,內容類型是非 XML 編碼的原則檔。

rawxml-link

原則檔不是 Xml 編碼,而且裝載於可從 API 管理服務存取的 HTTP 端點上。

xml

內容是內嵌的,內容類型是 XML 檔。

xml-link

原則 XML 檔裝載於可從 API 管理服務存取的 HTTP 端點上。

PolicyContract

原則合約詳細數據。

名稱 類型 預設值 Description
id

string

資源的完整資源標識碼。 例如 - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}

name

string

資源的名稱

properties.format

PolicyContentFormat

xml

policyContent 的格式。

properties.value

string

原則的內容,如格式所定義。

type

string

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

PolicyIdName

原則的標識碼。

Description
policy