Share via


Api Policy - Create Or Update

API için ilke yapılandırmasını oluşturur veya güncelleştirir.

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

URI Parametreleri

Name İçinde Gerekli Tür Description
apiId
path True

string

API düzeltme tanımlayıcısı. Geçerli API Management hizmet örneğinde benzersiz olmalıdır. Geçerli olmayan düzeltmede ; rev=n sonek olarak, burada n düzeltme numarasıdır.

Regex pattern: ^[^*#&+:<>?]+$

policyId
path True

PolicyIdName

İlkenin tanımlayıcısı.

resourceGroupName
path True

string

Kaynak grubunun adı. Ad büyük/küçük harfe duyarlı değildir.

serviceName
path True

string

API Management hizmetinin adı.

Regex pattern: ^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$

subscriptionId
path True

string

Hedef aboneliğin kimliği.

api-version
query True

string

Bu işlem için kullanılacak API sürümü.

İstek Başlığı

Name Gerekli Tür Description
If-Match

string

Varlığın ETag'i. Varlık oluştururken gerekli değildir, ancak varlığı güncelleştirirken gereklidir.

İstek Gövdesi

Name Gerekli Tür Description
properties.value True

string

İlkenin biçimiyle tanımlandığı şekilde içeriği.

properties.format

PolicyContentFormat

policyContent biçimi.

Yanıtlar

Name Tür Description
200 OK

PolicyContract

Kiracının API ilkesi yapılandırması başarıyla güncelleştirildi.

Headers

ETag: string

201 Created

PolicyContract

Api ilkesi yapılandırması başarıyla oluşturuldu.

Headers

ETag: string

Other Status Codes

ErrorResponse

İşlemin neden başarısız olduğunu açıklayan hata yanıtı.

Güvenlik

azure_auth

Azure Active Directory OAuth2 Flow.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation kullanıcı hesabınızın kimliğine bürünme

Örnekler

ApiManagementCreateApiPolicy
ApiManagementCreateApiPolicyNonXmlEncoded

ApiManagementCreateApiPolicy

Sample Request

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


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

Sample Response

{
  "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

Sample Request

PUT https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/5600b57e7e8880006a040001/policies/policy?api-version=2022-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"
  }
}

Sample Response

{
  "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>"
  }
}

Tanımlar

Name Description
ErrorFieldContract

Hata Alanı sözleşmesi.

ErrorResponse

Hata Yanıtı.

PolicyContentFormat

policyContent biçimi.

PolicyContract

İlke Sözleşmesi ayrıntıları.

PolicyIdName

İlkenin tanımlayıcısı.

ErrorFieldContract

Hata Alanı sözleşmesi.

Name Tür Description
code

string

Özellik düzeyi hata kodu.

message

string

Özellik düzeyi hatanın insan tarafından okunabilir gösterimi.

target

string

Özellik adı.

ErrorResponse

Hata Yanıtı.

Name Tür Description
error.code

string

Hizmet tanımlı hata kodu. Bu kod, yanıtta belirtilen HTTP hata kodu için bir alt durum görevi görür.

error.details

ErrorFieldContract[]

Doğrulama hatası durumunda istekte gönderilen geçersiz alanların listesi.

error.message

string

Hatanın insan tarafından okunabilen gösterimi.

PolicyContentFormat

policyContent biçimi.

Name Tür Description
rawxml

string

İçerikler satır içidir ve İçerik türü XML ile kodlanmamış bir ilke belgesidir.

rawxml-link

string

İlke belgesi XML olarak kodlanmaz ve API Management hizmetinden erişilebilen bir HTTP uç noktasında barındırılır.

xml

string

İçerikler satır içidir ve İçerik türü bir XML belgesidir.

xml-link

string

İlke XML belgesi, API Management hizmetinden erişilebilen bir HTTP uç noktasında barındırılır.

PolicyContract

İlke Sözleşmesi ayrıntıları.

Name Tür Varsayılan değer Description
id

string

Kaynağın tam kaynak kimliği. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}

name

string

Kaynağın adı

properties.format

PolicyContentFormat

xml

policyContent biçimi.

properties.value

string

İlkenin biçimiyle tanımlandığı şekilde içeriği.

type

string

Kaynağın türü. Örneğin, "Microsoft.Compute/virtualMachines" veya "Microsoft.Storage/storageAccounts"

PolicyIdName

İlkenin tanımlayıcısı.

Name Tür Description
policy

string