简体   繁体   English

如何在 Power Apps 中轻松返回流中的 API 响应到我的 canvas 应用程序?

[英]How do I easily return and API response from my flow to my canvas app in Power Apps?

Looking for some assistance, I have created a flow and a canvas app in power apps that calls an API, I finally got it to work but seems there has to be an easier way to do this.为了寻求帮助,我在调用 API 的强大应用程序中创建了一个流程和一个 canvas 应用程序,我终于让它工作了,但似乎必须有一种更简单的方法来做到这一点。

In my flow I'm taking the body and parsing it to get just what I need then returning the body of that response to the canvas app.在我的流程中,我获取正文并解析它以获得我需要的内容,然后将该响应的正文返回给 canvas 应用程序。 I could bypass that step and just return the body of the Api Call step, but my main question is, it seems a little to much to have to write some regex in my function when I click the button to call my flow.我可以绕过该步骤,只返回 Api 调用步骤的主体,但我的主要问题是,当我单击按钮调用流程时,必须在我的 function 中编写一些正则表达式似乎有点过分。

This creates the collection for me with the correct fields, but is there an easier way for the app to know my schema without having to manually define it?这会使用正确的字段为我创建集合,但是有没有更简单的方法让应用程序无需手动定义它就可以了解我的架构?

在此处输入图像描述

在此处输入图像描述

Use the new Power Platform CLI command that will automatically create a Power App from a REST API.使用新的Power Platform CLI 命令将自动从 REST API 创建 Power App。

在此处输入图像描述

在此处输入图像描述

If the only reason you're using Flow is to call the API from Power Apps, then yes, there is an easier way.如果您使用 Flow 的唯一原因是从 Power Apps 调用 API,那么是的,有一种更简单的方法。 You can create a Custom Connector and stop using Flow altogether.您可以创建自定义连接器并完全停止使用 Flow。

Steps:脚步:

  1. From make.powerapps.com , click Dataverse then Custom Connectorsmake.powerapps.com中,单击Dataverse ,然后单击Custom Connectors
  2. Click + New custom connector单击+ New custom connector
  3. Click Create from blank and name the Custom Connector单击Create from blank并将自定义连接器命名为
  4. Enter the host url (without the https:// )输入host url(没有https://
    • Keep the base url to /保持base url/
    • 在此处输入图像描述
  5. Click Security -->单击Security -->
  6. Select the correct security type Select 正确的安全类型
    • You can also select No authentication on this screen and use a request header on the Definition screen您也可以 select 在此屏幕上No authentication并在Definition屏幕上使用请求 header
    • 在此处输入图像描述
  7. Click Definition -->单击Definition -->
  8. Click New action then name the Summary , Description and Operation ID单击New action然后命名SummaryDescriptionOperation ID
    • 在此处输入图像描述
  9. Under Request click + Import from sample在“ Request ”下单击“ + Import from sample
  10. Select the method ( GET, POST, etc. ), enter the request URL and click Import -You'll want to paste in an example URL that has ALL required parameters. Select 方法( GET, POST, etc. ),输入请求 URL 并单击“ Import ”-您需要粘贴包含所有必需参数的示例 URL。
    - Example : https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&latitude=48.814963&longitude=-122.71135&maxradiuskm=50&orderby=magnitude-asc -示例https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&latitude=48.814963&longitude=-122.71135&maxradiuskm=50&orderby=magnitude-asc
    • 在此处输入图像描述
    • Note : This is where you could put an Authorization header if needed注意:如果需要,您可以在此处放置Authorization header
  11. Under Response click Default then Import from sampleResponse下点击Default然后Import from sample
    • Paste any required headers and the anticipated (typically JSON) response粘贴任何必需的标头和预期的(通常是 JSON)响应
    • I like to use Postman here...我喜欢在这里使用Postman ...
    • 在此处输入图像描述
  12. Click Import点击Import
    • 在此处输入图像描述
    • It's pretty nice how Power Apps parses the JSON response. Power Apps 解析 JSON 响应的方式非常好。 Each of these will be returned to your app.这些中的每一个都将返回到您的应用程序。 You can edit/delete/etc.您可以编辑/删除/等。
    • 在此处输入图像描述
  13. At this point, click Create connector此时,点击Create connector
  14. Scroll down and click Code preview -->向下滚动并单击Code preview -->
    • Don't mess with this unless you know what you're doing除非你知道自己在做什么,否则不要乱搞
  15. Click Test -->点击Test -->
  16. Click + New connection单击+ New connection
    • 在此处输入图像描述
  17. Depending on how you setup Security for this Custom Connector, you will either:根据您为此自定义连接器设置安全性的方式,您将:
    • Login using your Windows credentials使用您的 Windows 凭据登录
    • Paste in an API key粘贴 API 密钥
    • Or just click "Create" (as in my example which uses a free API)或者只需单击“创建”(如我使用免费 API 的示例)
      • If you used an Auth header in the Request area, this applies too如果您在Request区域使用了 Auth header,这也适用
    • 在此处输入图像描述
  18. Creating this Connection "kicks you out" of the Custom Connector creation screen.创建此连接会将您“踢出”自定义连接器创建屏幕。 You'll have to click Custom Connectors , select the one you just created, then click alllll the way through to the Test screen.您必须单击Custom Connectors select 您刚刚创建的那个,然后一直单击到Test屏幕。
  19. Once you're there, you should see the Connection has been made.到达那里后,您应该会看到已建立连接。
    • 在此处输入图像描述
  20. Enter the required parameters and click Test operation输入所需参数,然后单击Test operation
  21. You should see a Status 200 and the response body shown您应该看到状态 200 和显示的响应正文
    • 在此处输入图像描述
    • Pretty much done with the Custom Connector at this point.至此,自定义连接器已基本完成。
  22. Back in your Canvas PowerApp, click Add data and find the Custom Connector you just created返回您的 Canvas PowerApp,单击Add data并找到您刚刚创建的自定义连接器
    • 在此处输入图像描述
  23. Add a Button control and add this to the OnSelect property:添加一个Button控件并将其添加到OnSelect属性:
ClearCollect(colName, 
    'CustomConnectorName'.OperationID(
        {
            required_param1: "text",
            required_param2: 1234,
            required_paramN: "whatever",
        }
    )
)

Actual example :实际例子

ClearCollect(colEarthquakes, 
    '2022-11-27_SO_CustomConnector'.GETearthquakes(
        {
            format: "geojson",
            latitude: 48.814963,
            longitude: -122.71135,
            maxradiuskm: 50,
            orderby: "magnitude-asc"
        }
    )
)
  1. Click the Button control and investigate the response the Custom Connector returns.单击Button控件并调查自定义连接器返回的响应。 Depending on the shape of the JSON, you may need to "climb into" the nested JSON by using dot-notation in the ClearCollect() function.根据 JSON 的形状,您可能需要通过在ClearCollect() function 中使用点符号来“爬入”嵌套的 JSON。

This will get you close.这会让你接近。 If you want more, check out this video如果你想要更多,看看这个视频

Note: Custom Connectors are a premium feature.注意:自定义连接器是一项高级功能。 All users of the app will need either a PowerApps per-user or per-app license.该应用的所有用户都需要 PowerApps 每用户或每应用许可证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Power App - 来自 Flow 的响应不被视为 json - Power App - response from Flow is not treated as json 如何确保我的代码在 Power Apps 中按顺序执行? - How do I make sure that my code executes sequentially in Power Apps? 如何创建我自己的 API 并将其连接到 Power 应用程序? - How to create my own API and connect it to Power apps? 如何将参数从 Power Apps 发送到 Power Automate Flow - How to send parameters from Power Apps to Power Automate Flow 如何在 Canvas 应用程序中切换 Power Apps 数据连接 - How to SWITCH Power Apps Data Connection in Canvas App 如何使用 Canvas 应用程序在特定时间(而非计划)触发 Power 自动化流程? - How to trigger a Power automate flow at a specific time (not schedule) using Canvas app? 如何在我的电源应用程序中编写一个图标来触发我的相机控件的点击? - How to I program an icon in my power app to trigger a click of my camera control? 如何从 Power App Flow 中删除动态内容 HTTP_URIs(从 Power App 询问) - How to remove dynamic content HTTP_URIs(Ask from Power App) from Power App Flow 如何在 Power Apps 中对数据卡中的值执行 if 语句? - How do you do an if statement on a value from a datacard in Power Apps? 如何在 Power Apps 中创建禁用其他筛选器的筛选器 - How do I create a filter in Power Apps that disables other filters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM