限制通过Azure APIM要求的字段

发布于 2025-01-29 06:00:36 字数 975 浏览 3 评论 0原文

我们正在使用包裹在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[旋木] 2025-02-05 06:00:36

如果我正确理解的话,您只需要使用 set-Query-参数政策:

<set-query-parameter name="$select" exists-action="override ">
    <value>firstname,nickname</value>
</set-query-parameter>

If I understand correctly, all you need is to use set-query-parameter policy:

<set-query-parameter name="$select" exists-action="override ">
    <value>firstname,nickname</value>
</set-query-parameter>
薆情海 2025-02-05 06:00:36

您需要转换输入有效载荷。使用API​​M策略中的有效载荷转换逻辑。一个例子是使用液体模板并通过唯一必需的字段。您可以在此处参考文档: 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文