String concatenation issue with Azure Logic Apps
Asked Answered
I

2

7

I'm creating an ARM template that deploys an Web App (an Mvc Api) and a Logic App.

I'm attempting to define an HTTP Action within the Logic App such that it dynamically concatenates the base Uri of the Api as well as a property of the current item using splitOn and @triggerBody(). The base Uri itself is concatenated from a set of parameters in the ARM template into a variable variables('hockeyAppAPISettings').Uri.

Here's the relevant snipped of the action definition:

"actionName": {
  "conditions": [ ],
  "inputs": {
    "authentication": {
      "audience": "[variables('apiSettings').Authentication.Audience]",
      "clientId": "[variables('apiSettings').Authentication.ClientId]",
      "secret": "[variables('apiSettings').Authentication.Secret]",
      "tenant": "[variables('apiSettings').Authentication.Tenant]",
      "type": "ActiveDirectoryOAuth"
    },
    "method": "patch",
    "uri": "[concat(variables('apiSettings').Uri, '/@{triggerBody()['Id']}/ScanningInProgress')]"
    //"uri": "[concat(variables('apiSettings').Uri, '//@{triggerBody()[/'Id/']}//ScanningInProgress')]"
    //"uri": "[concat(variables('apiSettings').Uri, '//@@{triggerBody()[/'Id/']}//ScanningInProgress')]"
  },
  "type": "Http"
},

The "uri" section is what i'm struggling with. I've sprinkled various escape characters (\ and @) in differing patterns through out this.

I either can't get the deployment to succeed w/deployment errors like:

Unable to parse template language expression 'concat(variables('apiSettings').Uri, '//@{triggerBody()[/'Id/']}//ScanningInProgress')': expected token 'RightParenthesis' and actual 'Identifier'. Please see http://aka.ms/arm-template-expressions for usage details..'.

Or if I get the deployment working and then look at the code in the portal after deployment, the string concatenation doesn't seem to work properly. The variable doesn't get converted to its value.

I have validated that if I edit the Uri directly (via the portal HTML editor) using this: "uri" : "https://edited.azurewebsites.net/api/Packages/@{triggerBody()['Id']}/ScanningInProgress" the Logic App will make a patch call for each item that comes from the HTTP trigger.

What am I doing wrong?

Ifni answered 19/4, 2016 at 21:52 Comment(0)
O
14

You need to escape the inner single quotes, i.e. try

"uri": "[concat(variables('apiSettings').Uri, '/@{triggerBody()[''Id'']}/ScanningInProgress')]"

Alternatively you can use the dot notation to reference the property, i.e.

"uri": "[concat(variables('apiSettings').Uri, '/@{triggerBody().Id}/ScanningInProgress')]"
Onslaught answered 20/4, 2016 at 20:23 Comment(3)
Thanks @Szymon. I had tried something like the second variation you shared, but directly in the code view of the portal. It didn't work in the portal, so I didn't explore further using that in ARM templates. I just gave it a shot via ARM and it worked! I found it interesting that when I inspected the code view of Logic App in the portal after deployment, it transformed the "uri" property to one with @{triggerBody()['Id']}. It seems there are slight nuances between the two that I'm not quite up to speed on. Anyway, thanks so much for your help!Ifni
@Paul, glad to hear that it worked. Yes, there are certain expressions that the designer is not currently handling very well, so you need to be careful with saving the flow directly from the designer view if you have created it outside of the designer (since you could be using expressions that the designer does not handle well). We are working through any such issues, so with time the should be full compatibility between code view and designer view.Onslaught
how do we concatonate parameters with strings?Reservoir
C
0

For me changing this

"uri": "[concat(parameters('APIMUrl_param'), '/sales-management/differential-reference-codes/v1/?instance=', parameters('APIDRCInstance_param'), '&filter=differentialReferenceCode%20eq%27', variables('varDRC'), '%27')]",

to this has worked

"uri": "@concat(parameters('APIMUrl_param'), '/sales-management/differential-reference-codes/v1/?instance=', parameters('APIDRCInstance_param'), '&filter=differentialReferenceCode%20eq%27', variables('varDRC'), '%27')",
Coincidence answered 5/1, 2023 at 0:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.