0
votes

We just installed the API Connect 2018 version on our premises (installed in Openshift) and was trying to follow some examples I found in IBM tutorials. MY problem is that I cannot use Gatewayscript policy at all, since apim seems not to be defined at all.

I am trying a simple:

var req=apim.setvariable('message.body',"hello there!");

The exact error I get is: GatewayScript error: GatewayScript processing Error 'ReferenceError: apim is not defined. What am I missing here? Why "apim" seems to be defined in all IBM tutorials but not in our installation?

1
I came across this issue when trying the DataPower API Gateway (instead of DataPower Gateway v5 compatible). I noticed all the code of apim was not deployed to the gateway the same as it does on v5 compatible.. - EliSherer

1 Answers

0
votes

Background

API Connect 2018 provides two options for Gateways.

(1) DataPower Gateway - v5 compatible

This Gateway is compatible with APIC v5, and therefore the GatewayScript policy is as well. You do not need to do anything extra to be able to use apim.setvariable as you did not need to in v5.

(2) DataPower API Gateway

This is a new Gateway available in APIC 2018. It provides many improvements in interface. performance, debugability, etc. It is not fully backwards compatible. You seem to be using this new Gateway.


APIGW Options

You have two options for your particular example of apim.setvariable in a GatewayScript policy, while still using this APIGW:

(Option 1): Port your GatewayScript code to use the new functions available in GatewayScript in the new API Gateway. These should have better interfaces, better performance, and have many bugs fixed. In general they are documented here: https://www.ibm.com/support/knowledgecenter/en/SS9H2Y_7.7.0/com.ibm.dp.doc/context_apigw_js.html

The particular function you are looking for to set a variable in the API Context is documented here: https://www.ibm.com/support/knowledgecenter/en/SS9H2Y_7.7.0/com.ibm.dp.doc/context_apigw_js.html#context.set

To set a variable in the API Context as in your example above it would probably be: context.set('message.body',"hello there!");

(Option 2): If you want to be using the new APIGW for other advantages, but you also have GatewayScript policies which you don't have as much time to port and you're willing to stay with lower performance etc. for the time being on that part of your API, then for those GatewayScript policies, you can use the Compatibility Layer in the APIGW's GatewayScript Policy implementation.

This decreases your overall porting time, but some changes to your script might still be needed.

To use this Compatibility Layer, add to you GatewayScript the explicit line var apim = require('apim'); and then you can use the apim backward compatible functions.

For example, in your case in the question:

var apim = require('apim');
var req=apim.setvariable('message.body',"hello there!");

Why force you to add the extra line? One of the reasons is that it helps you make sure you're not accidentally using the Compatibility Layer on your new GatewayScripts that you write for API Connect 2018 and beyond. While the old functions are still available, by default it will try to help you only use the higher-performance newer functions. When needed, it's only one extra line at the top of the script.


Summary

Overall that leaves you three options with API Connect 2018 for your old APIC v5 GatewayScript policies: