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.


#API Connect
#Applicationintegration
#APIConnect
 View Only
  • 1.  Switch statement - using a header value

    Posted Thu March 27, 2025 05:08 PM

    Hi.  

    I'm trying to use a header value to route between different target-url's in a yaml file.   

    My question here is, do I need to either define this as a variable (color) or do I need to retrieve the value and set it to a variable to use in this switch statement?   The reason I ask, is when testing this, if I pass a header (color) and set the value to say blue, it's hitting my otherwise section... which leads me to believe it has a null value.

    execute:
          - switch:
              version: 2.0.0
              title: switch
              case:
                - condition: ($header(color) = blue)
                  execute:
                    - invoke:
                        version: 2.3.0
                        title: blue invoke
                        timeout: 60
                        verb: keep
                        chunked-uploads: false
                        persistent-connection: true
                        cache-response: protocol
                        cache-ttl: 900
                        target-url: $(olb-odc-blue-url)/$(api.operation.path)$(request.search)
                        tls-profile: paastlsprofile:1.0.0
                - condition: ($header(color) = green)
                  execute:
                    - invoke:
                        version: 2.3.0



    ------------------------------
    Jeff Bennett
    ------------------------------


  • 2.  RE: Switch statement - using a header value

    Posted Thu March 27, 2025 06:05 PM

    I believe you need to put both color and value in double quotes:

    condition: ($header("color") = "green")


    ------------------------------
    Matt
    ------------------------------



  • 3.  RE: Switch statement - using a header value

    Posted Mon March 31, 2025 11:09 AM

    Well thanks Matt!



    ------------------------------
    Jeff Bennett
    ------------------------------



  • 4.  RE: Switch statement - using a header value

    Posted Tue April 01, 2025 10:41 AM

    Hello Matt,

    I am also facing the same issue as mentioned by Jeff in thread. I tried your suggestion of using double quotes on both the key and value but it is not working. Any other way can I use to achieve to route the different invoke on the basis of header value.

    Thanks,



    ------------------------------
    Pawan Jinaga
    ------------------------------



  • 5.  RE: Switch statement - using a header value

    Posted Tue April 01, 2025 10:46 AM

    Can you share your code?  I tested this in 10.0.8 and it worked for all scenarios.



    ------------------------------
    Matt
    ------------------------------



  • 6.  RE: Switch statement - using a header value

    Posted Tue April 01, 2025 10:54 AM

    Hello Matt,

    I tried using ($(message.headers.Source)=="123") and it worked for me.

    Thanks,



    ------------------------------
    Pawan Jinaga
    ------------------------------