通过APIM 包装Power Automate HTTP Request

发布时间 2023-06-16 13:19:11作者: TheMiao

1. 首先需要在flow中创建“when a HTTP request is received”

 

当创建好,并且把body填写好保存之后, 会返回url

https://prod-27.southeastasia.logic.azure.com:443/workflows/febbc789e0ad4ed2b649b5f068bee657/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxxxxxxxxxxxxxxxxxxxxxx

 

后面我们需要设置Azure APIM Management

首先创建 blank API

 

 

 填写create blank API内容

 

 

根据需求我们填Display name, Name URL

并且点save 保存

 

 

点保存之后会进入到下面的页面

我们需要设置Backend > click Edit (笔)

 

 我们配置Backend HTTP(s)的界面如下

 

 同时我们也要配置policy

<!--
    IMPORTANT:
    - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.
    - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.
    - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.
    - To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.
    - To remove a policy, delete the corresponding policy statement from the policy document.
    - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.
    - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.
    - Policies are applied in the order of their appearance, from the top down.
    - Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.
-->
<policies>
    <inbound>
        <base />
        <rewrite-uri template="invoke?api-version=2016-06-01&-sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=yourkey" />
        <set-backend-service base-url="https://prod-27.southeastasia.logic.azure.com:443/workflows/febbc789e0ad4ed2b649b5f068bee657/triggers/manual/paths" />
    </inbound>
    <backend>
        <forward-request />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

  

 

最后我们可以做test

注意,我们要保护好Ocp-Apim-Subscription-Key的value。