We're using Azure Logic Apps to trigger various Runbooks.
As a part of these Logic Apps, we need to submit a JSON object to our Runbook as a string. This is so we can then validate the JSON object using a validation test based on the following logic:
During our testing, we've noticed that the Connector between Azure Logic Apps and Azure Automation is trying to be "too clever" by re-interpreting the object type.
This issue has also become apparent where we have a number of "switch" parameters which we've had to change to "boolean" parameters to get more predictable results, but this has brought its own challenges as listed below.
Some of the problems we've faced include:
Boolean values of True and False get converted to String values which then cause the error Cannot convert value "System.String" to type "System.Boolean"
Using Integer values of 0 ($false) and 1 ($true) to control boolean outcomes has proven more reliable, but is flagged as an error in the "Logic app designer" so cannot be saved unless updated through an ARM Template or in the "Logic app code view".
Simple string values seem to lose their enclosing double-quotes at random, but are still treated as strings, while more complicated examples require the double-quotes to be sent within the request.
When enclosing valid JSON within a String and trying to send to the Runbook, this seems to then get converted to an object and then the Runbook fails
Example
Using a specific example to illustrate this, if we take the following Logic App "Action" I'll explain the behaviors we observed:
The parameter named "test" is set to True as valid JSON boolean. When this is parsed to the Runbook, this gets interpreted as a String "$True". This results in an Error.
By contrast, the parameter named "NoMgAssignment" with an Interger value of 0 is correctly interpreted as a boolean $False.
Strings as Strings
The parameter named "RunAsAccount" is picked up correctly as a String even though the string value contains escaped double quotes around the value. In this instance, the double quotes appear in the value field when reviewing the Runbook Inputs.
The parameter named "clzId" is also picked up correctly as a String but the double quotes DO NOT appear in the value field when reviewing the Runbook Inputs.
JSON in Strings
The parameter named "inputVariablesAsJsonString" sends the body of the request from our trigger. This should be interpreted as a string, but the Runbook automatically converts this to an Object causing it to fail our validation test and any subsequent actions dependent on this being a String.
Focus on JSON in Strings
Focusing specifically on the last issue from above, we've had to implement the following in our Logic App code to get the correct behaviour from our "JSON in a String":
Append an escaped double quote to the beginning and end of the JSON input
Perform a 'replace' of a backslash character with a double-backslash (to correctly escape the escape character)
Perform a 'replace' of a double-quote character with an escaped double-quote (to correctly escape the double-quote character)
In code, this looks like the following... (note the additional escaping of the characters that we're escaping, due to this being within a JSON string itself):
As you can imagine, this is far from ideal and leaves us open to potential future problems as we're trying to manually re-factor valid JSON so it can be read by the Runbook as a String.
Summary
To remove the need to implement the workarounds described above, we would like to request an update to the connector between Azure Logic Apps and Azure Automation to allow correct handling of variable values and types from one system to the other.
If you have questions about Logic Apps, please visit the MSDN forums. The Issues section here is for questions about the artifacts in this GitHub repository.
Scenario
We're using Azure Logic Apps to trigger various Runbooks.
As a part of these Logic Apps, we need to submit a JSON object to our Runbook as a string. This is so we can then validate the JSON object using a validation test based on the following logic:
During our testing, we've noticed that the Connector between Azure Logic Apps and Azure Automation is trying to be "too clever" by re-interpreting the object type.
This issue has also become apparent where we have a number of "switch" parameters which we've had to change to "boolean" parameters to get more predictable results, but this has brought its own challenges as listed below.
Some of the problems we've faced include:
Example
Using a specific example to illustrate this, if we take the following Logic App "Action" I'll explain the behaviors we observed:
Booleans
Strings as Strings
JSON in Strings
Focus on JSON in Strings
Focusing specifically on the last issue from above, we've had to implement the following in our Logic App code to get the correct behaviour from our "JSON in a String":
In code, this looks like the following... (note the additional escaping of the characters that we're escaping, due to this being within a JSON string itself):
As you can imagine, this is far from ideal and leaves us open to potential future problems as we're trying to manually re-factor valid JSON so it can be read by the Runbook as a String.
Summary
To remove the need to implement the workarounds described above, we would like to request an update to the connector between Azure Logic Apps and Azure Automation to allow correct handling of variable values and types from one system to the other.