Adventures with Logic Apps: Handling Optional Query Parameters

Logic Apps

Ran into an interesting issue challenge with Logic Apps.

My Logic App sometimes takes a query parameter called planId.

I use the value of planIdto determine whether I should Insert or Update a record in a database.

If planId is not provided the statement triggerBody()['queries]['planId'] generates an exception.

This was very frustrating to figure out how to get around this.

Thankfully, I stumbled across an article at which pointed me in the direction of the fix.

It was pretty simple.

I just needed to add a couple of ? to the expression, so my original expression,triggerBody()['queries]['planId'], should be changed to triggerBody()?['queries]?['planId'].

Those ? are the key.

This will allow the parameter string and parameter to be missing and the code to not generate an exception.

Hope that helps!

Leave a Reply

Your email address will not be published.