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.  Unable to use the substring finction in the set variable policy

    Posted Thu August 24, 2023 10:32 AM

    Hi
    Hope this finds you well. 

    We have migrated from IBM API connect v5 to IBM API connect SaaS on AWS v10. However, in the migration, we need to compute the substring of "state" request parameter variable and pass to header so we have written following code 

    - set-variable:
    version: 2.0.0
    title: set-variable
    actions:
    - set: message.headers.state
    value: substring($(request.parameters.state), 0,3)
    type: string


    We are not getting the validation errors but the desired output is not produced. 

    Note: We are using the plan "base tier".

    Can someone help here what is the issue is it of the plan we are using or we are using wrong function.



    ------------------------------
    Pragnesh Gandhi
    ------------------------------


  • 2.  RE: Unable to use the substring finction in the set variable policy

    Posted Thu August 24, 2023 02:14 PM

    Hi Pragnesh,

    Per https://www.ibm.com/docs/en/api-connect/10.0.5.x_lts?topic=execute-set-variable, the value "Can be a literal value, or another variable." If you need to do a substring you'll need a GatewayScript policy that gets the variable from context, does the substring, and sets the new variable.  Also note that request.parameters.paramName actually returns an object of two arrays.   The first array is an array of strings with the location of the parameter (query, path, form) and the second array is an array of string values associated with the parameter at a particular location.  In most cases where you don't have the same parameter name in multiple locations, you'll get something like
    {"locations" : ["query"], "values": ["the value"]}

    so if you only have one location, you can safely do a context.get('request.parameters.state').values[0] and then do your substring of that.
    Best Regards,
    Steve Linn



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



  • 3.  RE: Unable to use the substring finction in the set variable policy

    Posted Fri August 25, 2023 08:51 AM

    I should call out that if you need to use a GatewayScript function, this is only available on the AWS Advanced plan, not the base Enterprise or free plan.



    ------------------------------
    Steven Cawn
    Sales
    IBM
    ------------------------------



  • 4.  RE: Unable to use the substring finction in the set variable policy

    Posted Fri September 22, 2023 05:07 AM
    Edited by Pragnesh Gandhi Fri September 22, 2023 05:08 AM

    Hi @Steve Linn
    Thank you for your reply. 



    ------------------------------
    Pragnesh Gandhi
    ------------------------------



  • 5.  RE: Unable to use the substring finction in the set variable policy

    Posted Fri September 22, 2023 05:06 AM
    Edited by Pragnesh Gandhi Fri September 22, 2023 05:08 AM

    Hi @Steven Cawn
    Thank you for your reply. 

    We are assuming that the substring function is not working as we have base plan and it doesnt support gateway script. Please correct our assumptions if we have assumptions wrong.

    ------------------------------
    Pragnesh Gandhi
    ------------------------------