简体   繁体   English

如何在逻辑应用中获取查询参数?

[英]How to get query parameters in a Logic App?

I'm trying to pass an extra query parameter to Azure logic app so that I can process below data in the Logic App workflow我正在尝试将额外的查询参数传递给 Azure 逻辑应用程序,以便我可以处理逻辑应用程序工作流中的以下数据

For Example https://logicURL?SelectedData= "%7BsiteURL%3AXYZ.sharepoint.com%2Fsites%2FXYZDev%7D" (encoded string)例如https://logicURL?SelectedData= "%7BsiteURL%3AXYZ.sharepoint.com%2Fsites%2FXYZDev%7D"(编码字符串)

In HTTP action I am trying to handle above passed data with below JSON schema在 HTTP 操作中,我尝试使用以下 JSON 模式处理以上传递的数据

{
    "kind": "Http",
    "inputs": {
        "schema": {
            "properties": {
                "selectedData": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    } }

I am not getting selectedData value.我没有得到 selectedData 值。 I need to use decodecomponentURI and then use the JSON value.我需要使用 decodecomponentURI 然后使用 JSON 值。

Azure logic app schema Azure 逻辑应用架构

Find the error here在这里找到错误

Azure logic app run time error Azure 逻辑应用运行时错误

First, you need to add your query param to the existing ones, eg首先,您需要您的查询参数添加到现有的,例如

https://xyz.logic.azure.com:443/workflows/id/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=code&SelectedData="%7BsiteURL%3AXYZ.sharepoint.com%2Fsites%2FXYZDev%7D"

https://xyz.logic.azure.com:443/workflows/id/triggers/manual/paths/invoke
  ?api-version=2016-10-01
  &sp=%2Ftriggers%2Fmanual%2Frun
  &sv=1.0
  &sig=code
  &SelectedData="%7BsiteURL%3AXYZ.sharepoint.com%2Fsites%2FXYZDev%7D"

Then, you should be able to get them in your Logic App using然后,您应该能够在您的逻辑应用程序中使用

@triggerOutputs()['queries']['SelectedData']

As you can see, there is no need to add a schema to the Http Trigger to get a query parameter可以看到,不需要在Http Trigger中添加schema来获取查询参数

Context语境

  • MSFT Azure Logicapp MSFT Azure 逻辑应用
  • MSFT Logicapp workflow definition language MSFT Logicapp 工作流定义语言
  • Live version as of 2020-06-25 04:56:31直播版本截至2020-06-25 04:56:31

Problem问题

  • Logicapp developer wants to obtain the value of a URL query parameter passed in via HTTP GET Logicapp 开发者想要获取通过 HTTP GET 传入的 URL 查询参数的值

Solution解决方案

  • The solution to this use-case is already provided elsewhere in this StackOverflow thread此用例的解决方案在此 StackOverflow 线程中的其他地方提供
  • This addon answer, however, refactors the previous solution然而,这个插件答案重构了以前的解决方案
    • it addresses constructing expressions in MSFT Workflow definition language (the JSON-based source code you see when viewing a logicapp in "code" view)它解决了在 MSFT 工作流定义语言中构建表达式(在“代码”视图中查看 logicapp 时看到的基于 JSON 的源代码)

Details细节

  • This URL extends the original question and another answer in this SO Thread此 URL 扩展了此 SO Thread 中的原始问题和另一个答案
  • Here we expect FirstName LastName and FaveColor properties这里我们期望FirstName LastNameFaveColor属性
https://xyz.logic.azure.com:443/workflows/id/triggers/manual/paths/invoke
      ?api-version=2016-10-01
      &sp=%2Ftriggers%2Fmanual%2Frun
      &sv=1.0
      &sig=code
      &FirstName=Huomer
      &LastName=Huimpson
      &FaveColor=
  • Standard init: The following is sufficient to capture the desired name-value pairs标准 init:以下内容足以捕获所需的名称-值对
triggerOutputs()['queries']['FirstName']
triggerOutputs()['queries']['LastName']
triggerOutputs()['queries']['FaveColor']
  • Error-trap init: The following is sufficient to capture the desired name-value pairs without throwing an error if any desired name-value pair is missing (error-free capture) Error-trap init:如果缺少任何所需的名称-值对,以下内容足以捕获所需的名称-值对而不会抛出错误(无错误捕获)
triggerOutputs()['queries']?['FirstName']
triggerOutputs()['queries']?['LastName']
triggerOutputs()['queries']?['FaveColor']
  • Error-trap init with defaults: The following is sufficient to error-trap init the desired name-value pairs, as well as provide a default value for any missing values带有默认值的错误陷阱初始化:以下内容足以错误陷阱初始化所需的名称-值对,并为任何缺失值提供默认
coalesce(triggerOutputs()['queries']?['FirstName']  , 'Puomer'  )
coalesce(triggerOutputs()['queries']?['LastName']   , 'Puimpson' )
coalesce(triggerOutputs()['queries']?['FaveColor']  , 'Purple' )

Solution refactored解决方案重构

  • Consequently, the original solution can be refactored as follows因此,原始解决方案可以重构如下
## BEFORE
@triggerOutputs()['queries']['SelectedData']

## AFTER
@{coalesce(triggerOutputs()['queries']?['SelectedData'] , '__blank__')}
  • This approach does what the typical use-case calls for, which is:这种方法可以满足典型用例的要求,即:
    • get the value if it exists,获取值,如果存在,
    • otherwise provide a default value, and否则提供默认值,和
    • don't crash the entire logicapp if the parameter was completely omitted如果完全省略参数,则不要使整个逻辑应用程序崩溃
    • the @{} syntax can be used if you are editing workflow definition language directly, but not if you are entering it in the "expression dialog box"如果您直接编辑工作流定义语言,则可以使用@{}语法,但如果您在“表达式对话框”中输入它,则不能使用

See also也可以看看

I am sending query String as:我将查询字符串发送为:

https://prod-17.westindia.logic.azure.com:443/workflows/f3b63b086e61420e8d76b7478f4b3e39/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=nESqZWY2NyAKKhCkaM0VnfenHuTqi1NSBjJdl9M5jNA&UserName=SecretName&Password=Nikita@123 https://prod-17.westindia.logic.azure.com:443/workflows/f3b63b086e61420e8d76b7478f4b3e39/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%&Ftriggers=%2Ftriggers=1 nESqZWY2NyAKKhCkaM0VnfenHuTqi1NSBjJdl9M5jNA&UserName=SecretName&Password=Nikita@123

I want to extract UserName in logic app.我想在逻辑应用程序中提取用户名。 For that I have used Compose connector and use following statement in expression.为此,我使用了 Compose 连接器并在表达式中使用了以下语句。

coalesce(triggerOutputs()['queries']?['UserName'] , ' blank ')合并(触发输出()['查询']?['用户名'],'空白')

I have tried this to:: triggerOutputs()['queries']?['UserName']我试过这个::triggerOutputs()['queries']?['UserName']

But I am getting one single blank space appended in front of UserName in output.但是我在输出中的 UserName 前面附加了一个空格。 Due to which, my condition is becoming false even if UserName is correct.因此,即使 UserName 正确,我的条件也会变得错误。

How to remove this extra space which is unnecessary appending to front.如何删除不必要的附加到前面的额外空间。 在此处输入图片说明

HTTP Connector Output as : HTTP 连接器输出为: 在此处输入图片说明

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

相关问题 如何获取逻辑应用指标? - How to get Logic App Metrics? 如何在部署逻辑应用程序时使用 salesforce API 连接的参数? - How to use parameters for salesforce API connection while deployment of Logic app? 在 Azure 逻辑应用程序中,如何在 http 请求中传递参数? - In Azure Logic App, how do I pass parameters in a http request? 如何使用 powershell 设置 azure 逻辑应用程序参数 - How to set azure logic app parameters using powershell 如何将查询结果填充到变量中并在逻辑应用程序中使用另一个查询 - How to stuff a result of a query into a variable and use it another query in a logic app 如何在逻辑应用程序中使用 HTTP 请求中传递的值/动态分配值给逻辑应用程序参数 - How to use values passed in HTTP Request in Logic Apps / Assign Values to Logic App Parameters Dynamically 如何在parameters.Azure Logic App Workflow定义中的parameters.json文件中使用参数 - How to use parameters inside parameters.json file in Azure Logic App Workflow definition 如何根据 Azure 逻辑应用中的 oData 请求有条件地查询表 - How to conditionally query tables based on oData request in an Azure Logic App 如何在逻辑应用表达式中检查 sql 执行查询数据是否为空? - How to check sql execute query data is null in logic app expression? Logic App中的过滤查询(OData) - Filter Query (OData) in Logic App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM