限制通过Azure APIM要求的字段
我们正在使用包裹在Dynamics365 API周围的Azure APIM。我们已经启动并运行它,但是我想做的是限制通过APIM返回的字段/属性。
即,我们有一种称为联系人的方法,但我不想返回200个字段,只是我们希望通过APIM暴露的字段。
关于如何在响应上执行此操作的演练,但我想根据初始请求过滤(即Web API中的选择)。
https://learn.microsoft.com/ en-us/azure/api-Management/Api-Management-Advanced-Policies
我尝试在入站标题中使用此命名法进行玩耍,但无济于事。
<choose>
<when condition="@(context.Response.StatusCode == 200 && context.Product.Name.Equals("Starter"))">
<set-body>@{
var response = context.Response.Body.As<JObject>();
foreach (var key in new [] {"current", "minutely", "hourly", "daily", "alerts"}) {
response.Property (key).Remove ();
}
return response.ToString();
}
</set-body>
</when>
</choose>
We are using Azure APIM wrapped around the Dynamics365 API. We have it up and running but what I would like to do is limit the fields/attributes that are returned via the APIM.
I.e., we have a method called Contacts, but I don't want to return 200 fields, just the ones we want to be exposed via the APIM.
There is a walkthrough on how to do this on the response, but I would like to filter on the initial request (i.e., the SELECT in the Web API).
https://learn.microsoft.com/en-us/azure/api-management/api-management-advanced-policies
I have tried playing around with this nomenclature in the INBOUND header to no avail.
<choose>
<when condition="@(context.Response.StatusCode == 200 && context.Product.Name.Equals("Starter"))">
<set-body>@{
var response = context.Response.Body.As<JObject>();
foreach (var key in new [] {"current", "minutely", "hourly", "daily", "alerts"}) {
response.Property (key).Remove ();
}
return response.ToString();
}
</set-body>
</when>
</choose>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解的话,您只需要使用 set-Query-参数政策:
If I understand correctly, all you need is to use set-query-parameter policy:
您需要转换输入有效载荷。使用APIM策略中的有效载荷转换逻辑。一个例子是使用液体模板并通过唯一必需的字段。您可以在此处参考文档: https://github.com/microsoftdocs/azure-docs/blob/main/main/main/articles/api-management/api-management/api-management-management-transensformation-procolation-polication-policies.md#using -liquid-templates-with-set-body
You need to transform the input payload. Use the payload transformation logic inside the APIM policy. One example is using liquid templates and passing the only required fields. You can refer the documentation here : https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/api-management/api-management-transformation-policies.md#using-liquid-templates-with-set-body