Currently, I am following some basic API Connect tutorials on IBM's platform. I am running these tutorials locally using Loopback, but I have hit a roadblock at an early stage.
Initially, I created a simple API service with some in-memory data and setter/getter functions. Following that, I developed a separate API which requires two GET parameters and utilizes one of the getter functions to conduct a search based on two specified criteria. Upon execution, I receive a response containing the following JSON object:
[{"itemId":1,"charge":9,"itemSize":2,"id":2}]
My subsequent attempt involved adding a server logic component to modify the response data by adding an additional field. At this stage, I am simply trying to include an extra field. I inserted a JavaScript component in the Assemble view and implemented the following code (extracted from a tutorial), with the intention to alter the message body returned by the API without disrupting the flow:
//APIC: get the payload
var json = apim.getvariable('message.body');
//console.error("json %s", JSON.stringify(json));
//same: code to inject new attribute
json.platform = 'Powered by IBM API Connect';
//APIC: set the payload
//message.body = json;
apim.setvariable('message.body', json);
Instead of obtaining an additional JSON parameter ("platform"), I encountered a 500 error each time I accessed the service. My assumption is that I may have made a fundamental error in my approach, even though all the documentation points towards the usage of correct variable names.