Original Message:
Sent: Tue July 16, 2024 03:27 AM
From: Celian Toureille
Subject: gateway script to include client.app.name in header
Hi Steve,
I use API Connect on the public cloud so I guess I'm stuck using my catches.
How can we make users write Javascript code without console logging... It took me way too long to make the work-around after two months of frustration. I thought a lot about quitting my job to escape API Connect because of this.
Please make a way to implement a debugger on the test tab of API Connect UI. It makes employees sad.
And make a lot of examples in the documentation. With fully build API you can download and study. I fell I don't have any clear guidelines on how to build my APIs properly.
If it wasn't for the book Digital Transformation and Modernization with IBM API Connect by Bryon Kataoka, James Brennan and Ashish Aggarwal I would have failed to produce any value with the software. Your answers on this forum are also highly valuable.
In hope someday this tool will be user friendly
------------------------------
Celian Toureille
Original Message:
Sent: Mon July 15, 2024 09:34 AM
From: Steve Linn
Subject: gateway script to include client.app.name in header
Hi Celian,
You need access to the DataPower appliance to use the GatewayScript debugger, something if you're using API Connect on the public cloud I'm sure you don't have, sorry. Information on the debugger is at https://www.ibm.com/docs/en/datapower-gateway/10.5.0?topic=gatewayscript-debuggers where your code would have a debugger;
statement in the execution flow that would act as a first breakpoint, but you have to also enable the debugger on the GatewayScript action associated with that code, something that you'd need to have DP access to do. I'm sure without this capability and access to the DataPower logs you're unit testing is difficult. I'll need to check with some colleagues to see if there is any documented guidance I can point you too.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Mon July 15, 2024 02:57 AM
From: Celian Toureille
Subject: gateway script to include client.app.name in header
Thank you Steve for your concerns.
The interface at https://cloud.ibm.com is a real mess and with so many things on my screen unrelated to my work that I fell lost most of the time. When I look at the documentation it's really really hard to find the right menus and tools.
I knew about DataPower, but when I read the documentation I don't get an url where I could log in with my IBM cloud account. I don't seem to find it in mainpage interface either. Explanations are all over the place and nothing leads me to the debugger I'm looking for.
Why don't we have the debugging window at the "Test" tab when using API Connect ?
If you have any idea on how to access this debugger it would be a tremendous help !
------------------------------
Celian Toureille
Original Message:
Sent: Fri July 12, 2024 05:18 PM
From: Steve Linn
Subject: gateway script to include client.app.name in header
Hi Celian,
Just to confirm you do not have access to the DataPower logs? I'm sure if you did you'd have seen the error with a stack trace there. If you're restricted from seeing the logs that does indeed make development much more difficult. Do you have any access to the DataPower appliance in your development environment where you could use the GatewayScript debugger? I've found that to be an invaluable tool but to use it you must have access to the appliance to enable the debugger on the DataPower GatewayScript Assembly action that references your code. If not, I'm afraid you'll need to do what you're doing in the API, perhaps using a default catch in case you have other errors beyond the JavaScriptError that you'd need similar information.
Best Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Fri July 12, 2024 03:23 AM
From: Celian Toureille
Subject: gateway script to include client.app.name in header
Solution :
context.message.header.set('appName', context.get('client.app.name'));
Further help :
Javascript error are seen as error 500, which doesn't help at all. You can make a workaround to see actual javascript errors.
First capture the javascript erro with a try catch
try { context.message.header.set('appName', context.get(client.app.name));} catch (error) { context.set('myJavascriptError', error); context.reject('JavaScriptError', 'Enter the error description you want');}
Next add a catch for JavaScriptError

Add the error informations to the session output
var error = context.get('error');var myJavascriptError = context.get('myJavascriptError');session.output.write({ "errorPolicyTitle": error.policyTitle, "errorTitle": error.message, "errorMessage": myJavascriptError.errorMessage, "errorCode": myJavascriptError.errorCode, "errorDescription": myJavascriptError.errorDescription, "errorSuggestion": myJavascriptError.errorSuggestion});
You will get with your code the following :
errorMessage: "client is not defined"
I don't know where to get the execution console. If anyone know it would be a great help for sure. When I have errors I want to see them without having to make this workaround ! IBM API Connect should, in the test tab, returns javascript errors. The fact that it's not natively implemented is really harmful to the user.
Anyway, this technique is really nice cause when I get an error in production the error is written in the logs. I know what Gateway had an error, and why. The output for the client do not returns all theses informations. Only the internal error and the log_id associated with the error.
I plan to increase the information of my error logs in the near future. If you guys have any suggestion to add I would be glad :)
------------------------------
Celian Toureille
Original Message:
Sent: Thu July 11, 2024 03:56 PM
From: Jeff Bennett
Subject: gateway script to include client.app.name in header
I'm trying to add a gateway script to a yaml to add a header which is sent to the backend containing the client.app.name but it's not currently working.
I'm using this:
- gatewayscript:
title: add-appname-header
version: 2.0.0
source: context.message.header.set('appName', context.get(client.app.name));
Anyone have any similar examples or something that is functioning?
------------------------------
Jeff Bennett
------------------------------