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.  Calculate date difference in API Connect Gateway Script

    Posted Wed August 16, 2023 09:33 AM

    Hi Team...

    We wanted to implement the below logic in API Connect Gateway script

    1. Find the difference between two dates (date format is YYYY-MM-DD)
    2. Find out the whether difference exceeds 'X' days
    3. If so, throw the error to the consumer.

    Please advise how can we achieve in APIC Gateway script. 



    ------------------------------
    Ashok Beshra
    ------------------------------


  • 2.  RE: Calculate date difference in API Connect Gateway Script

    Posted Thu August 24, 2023 02:36 PM

    Hi Ashok,
    I found this example https://www.javatpoint.com/javascript-date-difference which calculates the number of days, so if that calculation exceed 'X' days do a context.reject and set the desired HTTP status code.   For the latter, see https://www.ibm.com/docs/en/api-connect/10.0.5.x_lts?topic=aplc-using-context-variables-in-gatewayscript-xslt-policies-datapower-api-gateway  and look for context.reject.
    Best Regards,

    Steve



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



  • 3.  RE: Calculate date difference in API Connect Gateway Script

    Posted Fri August 25, 2023 03:49 AM

    Thanks a lot Champ Steve! It worked.



    ------------------------------
    Ashok Beshra
    ------------------------------