API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Switch to Bypass JSON Validation for Empty Bodies

  • 1.  Switch to Bypass JSON Validation for Empty Bodies

    Posted Thu March 21, 2024 10:10 AM

    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:

    1. Placing a no-op GatewayScript 
    2. 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
    ------------------------------


  • 2.  RE: Switch to Bypass JSON Validation for Empty Bodies

    Posted Thu March 28, 2024 11:25 AM

    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
    ------------------------------