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.  Catalog Properties usage in catalog settings

    Posted Fri September 13, 2024 03:53 AM

    Hi,

    We're trying to use Catalog Properties in the "Catalog Settings" section. Using the below statement to get the value of the property in the API.

    var toggle = "$(counterapi-toggle)";

    apim.setvariable('enableCounter',toggle);

    The extraction of the value is working but when the value is changed to another - the updated value is not being set to the variable. Instead, the older value itself is being fetched. Cloud anyone please help us understand if we're missing something and also, how long it ideally takes to fetch the updated value. 

    Thanks, Tanuja

    @Steve Linn - Could you please help me with this?



    ------------------------------
    Tanuja Ede
    ------------------------------


  • 2.  RE: Catalog Properties usage in catalog settings

    Posted Fri September 13, 2024 01:48 PM

    Hi Tanjja,
    A catalog property is substituted by the API Manager at time of publish.  If you change a catalog property value, those already published APIs will maintain the old value until they are republished which is where the substitution of the new catalog property value would happen.  As far as the Gateway is concerned, it knows nothing about a catalog property.  What is deployed to the Gateway would have the actual current value.

    Best Regards,
    Steve Linn



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



  • 3.  RE: Catalog Properties usage in catalog settings

    Posted Mon September 16, 2024 01:28 AM

    Hi Steve,

    Thanks so much for the response. But do you think there is any way to configure a flag and make use of it without touching the code each time there are minor changes in the API related to flag's value?

    Thanks,

    Tanuja.



    ------------------------------
    Tanuja Ede
    ------------------------------



  • 4.  RE: Catalog Properties usage in catalog settings
    Best Answer

    Posted Mon September 16, 2024 05:47 PM

    Hi Tanuja,
    Catalog properties are only known to the API Manager, so there is nothing you can do that wouldn't require a publish to update your APIs that use this catalog property when you change the value.  As for changing "code", I don't like seeing GatewayScript code as you have above, specifically var toggle = "$(counterapi-toggle)"; The API Manager on publish is modifying your code upon publish.  What I'd prefer to see in this case as having a set variable policy prior to your GatewayScript policy that would set a variable named counterapi-toggle with a type of any and a value of $(conterapi-toggle).  Then you GatewayScript would use

    var toggle = apim.getvariable('counterapi-toggle');
    apim.setvariable('enableCounter',toggle);

    Now your GatewayScript is always the same, but the set-variable will create a Gateway property in context with the value of your catalog property so the GatewayScript can access that value using a context get function instead of having your code changed with a variable substitution every publish.  Perhaps this is a subtle difference in that you still need to do the publish to get the updated value in place, but the update impacts the set variable policy configuration, not the GatewayScript code.  Also, as for your example, I would suggest using the API Gateway native context object (assuming you're not using a v5 compatible gateway), ie

    var toggle = context.get('counterapi-toggle');
    context.set('enableCounter',toggle);


    Best Regards,
    Steve Linn



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



  • 5.  RE: Catalog Properties usage in catalog settings

    Posted 22 days ago

    hi Steve,

    could you guide me to get the catalog properties I created in catalog properties inside catalog settings from manage tab, how can I get them inside a gatewayscript used in the api flow ( I've checked I'm using the same catalog ) I used => apim.getvariable('catalog.properties.u*******e') =>  

    could you advise how I could get these values ??? should I add them inside the api cataloge properties inside the api itself ?



    ------------------------------
    Basma Hesham
    ------------------------------



  • 6.  RE: Catalog Properties usage in catalog settings

    Posted 22 days ago

    Hi,

    you can access as context.get('variable name')

    or you can refer as $(variableName) in gateway script. 



    ------------------------------
    pratap vadlapati
    ------------------------------



  • 7.  RE: Catalog Properties usage in catalog settings

    Posted 22 days ago

    Hi Pratap,

    Have you tried this in a script before ??

    I tried the 2 methods one is returning undefined and the other is returning a syntax error as $ is not defined.

    var password_prop = apim.getvariable('password');
    var password_prop = $(catalog.properties.password);



    ------------------------------
    Basma Hesham El Sayed
    IBM Integration Engineer
    First Abu Dhabi Bank (FabMisr)
    ------------------------------



  • 8.  RE: Catalog Properties usage in catalog settings

    Posted 22 days ago

    Hi Pratap and Basma,

    In GatewayScript, variable substitution in the source code using $(varname) is not supported in APIC v10 as it was a security concern for code substitution.  You must use context.get of the variable name.  Having said that, as noted earlier in this thread I believe, catalog properties are substituted at publish time, not runtime, so the proper method is to use a set variable policy to set some variable you name for use in your API such as myu****e using the variable source of $(catalogvariablename) ... note not catalog.properties.u*******e but simply u*******e.  The GatewayScript would then use context.get('myu*****e').

    Regards,

    Steve



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



  • 9.  RE: Catalog Properties usage in catalog settings

    Posted 22 days ago
    Hello,

    Yes I use it everyday.
    Which version of APIC are you on?
    No need to give catalog.variable unless you define the same.

    The below should work on v10 and will support according APIC functions if you are on lower versions.

    var password_prop = $(variableName);
    var password_prop = context.get('variableName');


    Thanks