Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring and using a "parameter" in Logic Apps

In my file

LogicApp.parameters.json

I've declared the extra parameter called MyFirstNewParameter

full file contents below

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "logicAppName": {
      "value": "MyFirstLogicAppOne"
    },
    "servicebus_1_connectionString": {
      "value": "Endpoint=sb://notForYouToSee"
    },
    "MyFirstNewParameter": {
      "value": "abc123"
    }
  }
}

In my LogicApp.json file, I've added the "declaration" of MyFirstNewParameter.

in the

"parameters": {}

area (4th line below is where that section starts)

And I've also added a simple response that tries to read the parameter value and send it back in the response. (Named "Read_And_Use_Parameter_Value_Simple_Response" of all things)

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "logicAppName": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "metadata": {
        "description": "Name of the Logic App."
      }
    },
    "logicAppLocation": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "allowedValues": [
        "eastasia",
        "southeastasia",
        "centralus",
        "eastus",
        "eastus2",
        "westus",
        "northcentralus",
        "southcentralus",
        "northeurope",
        "westeurope",
        "japanwest",
        "japaneast",
        "brazilsouth",
        "australiaeast",
        "australiasoutheast",
        "southindia",
        "centralindia",
        "westindia",
        "canadacentral",
        "canadaeast",
        "uksouth",
        "ukwest",
        "westcentralus",
        "westus2",
        "[resourceGroup().location]"
      ],
      "metadata": {
        "description": "Location of the Logic App."
      }
    },
    "MyFirstNewParameter": {
      "type": "string",
      "metadata": {
        "description": "Name of the MyFirstNewParameter."
      },
      "defaultValue": "My1NewParameterDefaultValue"
    }
  },
  "variables": {},
  "resources": [
    {
      "name": "[parameters('logicAppName')]",
      "type": "Microsoft.Logic/workflows",
      "location": "[parameters('logicAppLocation')]",
      "tags": {
        "displayName": "LogicApp"
      },
      "apiVersion": "2016-06-01",
      "properties": {
        "definition": {
          "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
          "actions": {
            "Read_And_Use_Parameter_Value_Simple_Response": {
              "type": "Response",
              "inputs": {
                "statusCode": 200,
                "body": "The parameter value is ***@{parameters('MyFirstNewParameter')}***"
              },
              "runAfter": {}
            }
          },
          "parameters": {},
          "triggers": {
            "manual": {
              "type": "Request",
              "kind": "Http",
              "inputs": {
                "schema": {}
              }
            }
          },
          "contentVersion": "1.0.0.0",
          "outputs": {}
        },
        "parameters": {}
      }
    }
  ],
  "outputs": {}
}

enter image description here

When I sent a request I get the below in the client:

{
    "error": {
        "code": "NoResponse",
        "message": "The server did not received a response from an upstream server. Request tracking id '000000000000000000000'."
    }
}

When I check the portal, the following error is generated:

InvalidTemplate. Unable to process template language expressions in action 'Read_And_Use_Parameter_Value_Simple_Response' inputs at line '1' and column '1232': 'The workflow parameter 'MyFirstNewParameter' is not found.'.

Do what?

How do I "read" parameters defined in LogicApp.parameters.json in the Logic App?

Urls of interest

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language#parameters

APPEND WITH WORKING CORRECTLY CODE

The accepted answer shows there is ambiguity with the sets of parameters.

Here is the corrected working answer with un-ambiguous names.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "logicAppName": {
      "value": "MylogicAppName"
    },
    "MyFirstNewArmParameter": {
      "value": "ValueIWantToSeeShowUp"
    }
  }
}

and

   {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "logicAppName": {
        "type": "string",
        "minLength": 1,
        "maxLength": 80,
        "metadata": {
          "description": "Name of the Logic App."
        }
      },
      "logicAppLocation": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "allowedValues": [
          "eastasia",
          "southeastasia",
          "centralus",
          "eastus",
          "eastus2",
          "westus",
          "northcentralus",
          "southcentralus",
          "northeurope",
          "westeurope",
          "japanwest",
          "japaneast",
          "brazilsouth",
          "australiaeast",
          "australiasoutheast",
          "southindia",
          "centralindia",
          "westindia",
          "canadacentral",
          "canadaeast",
          "uksouth",
          "ukwest",
          "westcentralus",
          "westus2",
          "[resourceGroup().location]"
        ],
        "metadata": {
          "description": "Location of the Logic App."
        }
      },
      "MyFirstNewArmParameter": {
        "type": "string",
        "metadata": {
          "description": "Name of the MyFirstNewArmParameter."
        },
        "defaultValue": "My1NewArmParameterDefaultValue"
      }
    },
    "variables": {

    },
    "resources": [{
        "name": "[parameters('logicAppName')]",
        "type": "Microsoft.Logic/workflows",
        "location": "[parameters('logicAppLocation')]",
        "tags": {
            "displayName": "LogicApp"
        },
        "apiVersion": "2016-06-01",
        "properties": {
            "definition": {
                "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                "actions": {
                    "Read_And_Use_Parameter_Value_Simple_Response": {
                        "type": "Response",
                      "inputs": {
                        "statusCode": 200,
                        "body": "The parameter value is ***@{parameters('MyFirstNewLogicAppParameter')}***"
                      },
                        "runAfter": {

                        }
                    }
                },
              "parameters": {
                "MyFirstNewLogicAppParameter": {
                  "type": "string",
                  "defaultValue": "MyFirstNewLogicAppParameterDefaultValue"
                }
              },
                "triggers": {
                    "manual": {
                        "type": "Request",
                        "kind": "Http",
                        "inputs": {
                            "schema": {

                            }
                        }
                    }
                },
                "contentVersion": "1.0.0.0",
                "outputs": {

                }
            },
            "parameters": {
              "MyFirstNewLogicAppParameter": {
                "value": "[parameters('MyFirstNewArmParameter')]"
              }
            }
        }
    }],
    "outputs": {

    }
}

The client now receives the anticipated value

**The parameter value is ***ValueIWantToSeeShowUp*****

I also found this article:

http://blog.ibiz-solutions.se/integration/logic-apps-parameters-vs-arm-parameters/

The first paragraph of the articles is below, in case the url stops working in the future (to maybe internet-search if it gets moved)

Logic Apps Parameters vs ARM Parameters I got the question about what the difference is between ARM template parameters and Logic App parameters and when these should be used, so that is what I’ll try to explain in this post. First of ARM template paramters are used with ARM templates and the ARM template is used when deploying ARM based resources to Azure and Logic App’s is a resource that is deployed via ARM templates. The workflow definition language behind Logic App’s is very similar to ARM templates and therefore it can be tricky to see the difference in the beginning.

Author: Mattias Lögdberg

like image 588
granadaCoder Avatar asked Sep 06 '17 18:09

granadaCoder


People also ask

What does the condition parameter in logic apps allow you to do?

To run specific actions in your logic app only after passing a specified condition, add a condition action. This control structure compares the data in your workflow against specific values or fields. You can then specify different actions that run based on whether or not the data meets the condition.


1 Answers

I know it's very confusing, but there are ARM Template parameters and LogicApp parameters. You just declared the ARM parameter, but missed the LogicApp one. Then you can pass the ARM parameter to the LogicApp parameter.

Try this:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "metadata": {
                "description": "Name of the Logic App."
            }
        },
        "logicAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "allowedValues": ["eastasia",
            "southeastasia",
            "centralus",
            "eastus",
            "eastus2",
            "westus",
            "northcentralus",
            "southcentralus",
            "northeurope",
            "westeurope",
            "japanwest",
            "japaneast",
            "brazilsouth",
            "australiaeast",
            "australiasoutheast",
            "southindia",
            "centralindia",
            "westindia",
            "canadacentral",
            "canadaeast",
            "uksouth",
            "ukwest",
            "westcentralus",
            "westus2",
            "[resourceGroup().location]"],
            "metadata": {
                "description": "Location of the Logic App."
            }
        },
        "MyFirstNewParameter": {
            "type": "string",
            "metadata": {
                "description": "Name of the MyFirstNewParameter."
            },
            "defaultValue": "My1NewParameterDefaultValue"
        }
    },
    "variables": {

    },
    "resources": [{
        "name": "[parameters('logicAppName')]",
        "type": "Microsoft.Logic/workflows",
        "location": "[parameters('logicAppLocation')]",
        "tags": {
            "displayName": "LogicApp"
        },
        "apiVersion": "2016-06-01",
        "properties": {
            "definition": {
                "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                "actions": {
                    "Read_And_Use_Parameter_Value_Simple_Response": {
                        "type": "Response",
                        "inputs": {
                            "statusCode": 200,
                            "body": "The parameter value is ***@{parameters('MyFirstNewParameter')}***"
                        },
                        "runAfter": {

                        }
                    }
                },
                "parameters": {
                    "MyFirstNewParameter": {
                        "type": "string"
                    }
                },
                "triggers": {
                    "manual": {
                        "type": "Request",
                        "kind": "Http",
                        "inputs": {
                            "schema": {

                            }
                        }
                    }
                },
                "contentVersion": "1.0.0.0",
                "outputs": {

                }
            },
            "parameters": {
                "MyFirstNewParameter": {
                    "value": "[parameters('MyFirstNewParameter')]"
                }
            }
        }
    }],
    "outputs": {

    }
}

Some tips and tricks on how to prepare Logic Apps for CI/CD using ARM Templates and parameters in this link: https://platform.deloitte.com.au/articles/preparing-azure-logic-apps-for-cicd

HTH

like image 109
Paco de la Cruz Avatar answered Sep 22 '22 07:09

Paco de la Cruz