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
  • 1.  Client IP Address on Condition Editor

    Posted Wed December 20, 2023 10:31 AM

    Hello,

    I am trying to put some condition to allow the API call from specific client IP . to achieve that I am trying to fetch the IP Address as follows , it's not working for me on APIC 10.X

    session.ClientAddress == 'X.XXX.XXX.XXX'

    A quick help is much appreciate !!!

    Also if I want to debug on certain variables , how can I do that.

    Regards,

    Rajesh Swain 



    ------------------------------
    Rajesh Swai
    ------------------------------



  • 2.  RE: Client IP Address on Condition Editor

    Posted Tue January 02, 2024 03:25 PM

    Hi,

    You can retrieve and compare Client IP address like this: message.headers.x-client-ip == 'X.XXX.XXX.XXX'

    This format was changed after API Connect v5.

    I hope this helps. Please reach out with any follow-up questions.



    ------------------------------
    Ruchi Yadav
    ------------------------------



  • 3.  RE: Client IP Address on Condition Editor

    Posted Thu January 04, 2024 03:40 PM

    Hi Rajesh,
    See https://www.ibm.com/docs/en/api-connect/10.0.5.x_lts?topic=reference-api-connect-context-variables, the variable name has a lower case c not a capital C, ie, session.clientAddress.
    Best Regards,
    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 4.  RE: Client IP Address on Condition Editor

    Posted Thu March 28, 2024 09:52 AM

    HI All,

    We working in IBM APIC SaaS Base Edition.

    In both case where we specify message.headers.x-client-ip == 'XXX.XXX.XXX.XXX' or session.clientAddress == 'XXX.XXX.XXX.XXX', we get a syntax error.

    However when we specify $apiCtx().session.clientAddress = 'xxx.xxx.xxx.xxx' or $apiCtx().message.headers.x-client-ip = 'xxx.xxx.xxx.xxx', it works.

    Thanks,

    Paul



    ------------------------------
    Paul Dango
    ------------------------------



  • 5.  RE: Client IP Address on Condition Editor

    Posted Thu March 28, 2024 11:18 AM

    Hi Paul, 
    Since the SaaS Base Edition doesn't support the GatewayScript policy, I'm assuming the syntax you're showing is from a switch conditional.   Switch conditionals use JSONata syntax where you'd use a single = equality operator, whereas the == is JavaScript syntax for an equality operator.  If you were to make that change, do you still require the $apiCtx() function?

    Regards,

    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------



  • 6.  RE: Client IP Address on Condition Editor

    Posted Thu March 28, 2024 12:21 PM
    HI Steve,

    Changing to '=' as the equality operator works.

    It is no longer required to use  the $apiCtx()function.

    Thanks,

    Paul