What is the proper syntax to check if a particular property is returned in a HTTP response?
I am checking for low battery levels using the https://lab.sharptools.dev/smartthings/batterycheck URI. I want to send an email only when devices are returned. When I check if $context.response.data.textSummary is not “” the step fails, assuming because it doesn’t exist in the response.
I could also check the count of $context.response.data.items but that also is absent in the response when there aren’t any low battery devices.
For the record, this is my response when there are no devices returned:
textSummary property, I would have thought checking for an empty string would work. Note that when you see a value of
"value": "" that doesn’t mean that you would enter double quotes in the condition (
""). Instead, it would mean a completely empty field (you’ll likely need to enter something in the field and then delete it so it’s an empty string):
Note that this is not the same as checking for the existence of a field. In this case, the
textSummary field should always be included in the response… it’s just that the field will be an empty string when there is no match.
If you wanted to check for the existence of a field, you could use an expression with the
isEmpty() function to set a boolean. This post and this post are good examples showing the
isEmpty() function in action.
Thanks Josh, this helped. Here is a screenshot for reference in case anyone else is trying to do something similar.