如何导出API及操作级有效策略至XML文件?已尝试curl未成功
获取Azure APIM API/操作级别的有效策略
你当前调用的API只能返回直接分配给目标API的策略,而Azure APIM的有效策略是全局、产品、API、操作多层级策略合并后的结果,需要使用专门的有效策略查询接口来获取:
API级别有效策略请求
curl --location 'https://management.azure.com/subscriptions/xxxxxxxxxxxx/resourceGroups/xxxxxxxxx/providers/Microsoft.ApiManagement/service/xxxxxxxxxx/apis/apiname/policies/effective?format=xml&api-version=2022-08-01' \ --header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
操作级别有效策略请求
只需在路径中追加操作ID即可:
curl --location 'https://management.azure.com/subscriptions/xxxxxxxxxxxx/resourceGroups/xxxxxxxxx/providers/Microsoft.ApiManagement/service/xxxxxxxxxx/apis/apiname/operations/{operationId}/policies/effective?format=xml&api-version=2022-08-01' \ --header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
关键说明
- 核心改动是将原请求路径中的
policy替换为effective,这个接口会自动整合所有层级的策略,返回实际生效的完整内容 - 接口返回的XML包含了全局策略、关联产品的策略、API自身策略(以及操作级策略,如果是操作请求)的合并结果
- 确保你的Bearer令牌拥有
Microsoft.ApiManagement/service/apis/policies/effective/read的权限
内容的提问来源于stack exchange,提问作者Vowneee
相关产品推荐
相关产品推荐

