Hi Soulaiman,
I tried
condition: (message.body and $string(message.body) != "")
which worked. I was having issues with the single quotes, but when I tried double quotes it worked as expected. I'd think single quotes should work, so that may be a product issue that you should open a support ticket. Again note that if your API is buffering, the above will work, but if you are streaming, message.body will be null. You should have a condition that checks the HTTP method for a POST or PUT and does a Parse policy for those. That will read the data off of the stream and would the parse would populate message.body.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Thu March 21, 2024 10:10 AM
From: Soulaiman El Maimouni
Subject: Switch to Bypass JSON Validation for Empty Bodies
Hello,
I'm encountering a challenge in IBM API Connect where I need to bypass JSON validation for requests with empty bodies. My approach involves using a switch condition $string(message.body) != ""
to detect non-empty bodies for validation. However, this condition fails to work as intended unless I insert a non-operational GatewayScript policy anywhere in the assembly.
Here's what I've tried:
- Placing a no-op GatewayScript
- Using the switch condition to attempt bypassing validation for empty bodies.
Oddly, the switch only works with the GatewayScript in place. Does anyone know why this happens, or how to implement this bypass more directly without such workarounds?
Appreciate any insights or suggestions!
Thank you.
------------------------------
Soulaiman El Maimouni
------------------------------