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

use*_*797 12 azure azure-logic-apps workflow-definition-language

我正在尝试将额外的查询参数传递给 Azure 逻辑应用程序,以便我可以处理逻辑应用程序工作流中的以下数据

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

在 HTTP 操作中,我尝试使用以下 JSON 模式处理以上传递的数据

{
    "kind": "Http",
    "inputs": {
        "schema": {
            "properties": {
                "selectedData": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    } }
Run Code Online (Sandbox Code Playgroud)

我没有得到 selectedData 值。我需要使用 decodecomponentURI 然后使用 JSON 值。

Azure 逻辑应用架构

在这里找到错误

Azure 逻辑应用运行时错误

Pac*_*ruz 14

首先,您需要您的查询参数添加到现有的,例如

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"
Run Code Online (Sandbox Code Playgroud)

然后,您应该能够在您的逻辑应用程序中使用

@triggerOutputs()['queries']['SelectedData']
Run Code Online (Sandbox Code Playgroud)

可以看到,不需要在Http Trigger中添加schema来获取查询参数


dre*_*mac 7

Context

  • MSFT Azure Logicapp
  • MSFT Logicapp workflow definition language
  • Live version as of 2020-06-25 04:56:31

Problem

  • Logicapp developer wants to obtain the value of a URL query parameter passed in via HTTP GET

Solution

  • The solution to this use-case is already provided elsewhere in this StackOverflow thread
  • 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)
    • it addresses the case where a missing name-value pair can cause the entire Logicapp to terminate. We do not want that to happen, so we process name-value pairs in an error-free way

Details

  • This URL extends the original question and another answer in this SO Thread
  • Here we expect FirstName LastName and FaveColor properties
    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
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)
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