Good catch. The internal server was due to the missing input parameters in the Weather Api. Now, I moved the implementation to CityApi which is to call WeatherApi. The Weather Api will returns the city as part of its response
curl -kv "https://dpnano-weather-sandbox-api-connect-jh.api-n-abxn.trial.apiconnect.ibmappdomain.cloud/1/cityapi/citydetails?city=Toronto" -H "Accept: application/json" -H "X-IBM-Client-Id: 763d3a917b2dbe5a346a19e08a36057f" -H "X-IBM-Client-Secret: 1f395ca3131fbd9dccd8315ea3f6c371"
Original Message:
Sent: 07/08/26 03:41 AM
From: GARY TU
Subject: how to intercept the URL input argument with luascript
Hi Michael,
I suspect the error is caused by no any query parameters in your test url. You can try to look the logs to verify what kind of error it reports, and also try to append "?city=Toronto&country=CA" in test url to see if it works.
------------------------------
Gary Tu
Software Developer, DataPower
------------------------------
Original Message:
Sent: 07/08/26 02:25 AM
From: Michael Liu
Subject: how to intercept the URL input argument with luascript
Hi, Gary
Tx for your reply, below is the test result:
it was working as below:

You can call it with:
curl -kv "https://mock-weather-sandbox-api-connect-jh.api-n-abxn.trial.apiconnect.ibmappdomain.cloud/1.0/mockenvironment/mock-temperature" -H "Accept: application/json" -H "X-IBM-Client-Id: 763d3a917b2dbe5a346a19e08a36057f" -H "X-IBM-Client-Secret: 1f395ca3131fbd9dccd8315ea3f6c371"
However, with the newly added red line which is implemented as below:

Which has implementation as:
kind: Set
apiVersion: api.ibm.com/v1
metadata:
name: Mock_QueryParameters
namespace: Mock_Product_Weather
version: '1'
tags: []
labels:
gatewayTypes:
- nano
spec:
valueType: jsonata
variable:
name: queryParams
value: $queryParameters("request")
I got the following result:

I suspect $queryParameters("request") does not work in nano dp
Regards,
Michael Liu
------------------------------
Michael Liu
------------------------------
Original Message:
Sent: 07/07/26 10:29 PM
From: GARY TU
Subject: how to intercept the URL input argument with luascript
Hi Michael,
I want to ensure I've understood your requirements correctly. The snippet provided should allow you to extract the 'city' query parameter for LuaScript, as per your original example. Please let me know if this aligns with what you were looking for.
------------------------------
Gary Tu
Software Developer, DataPower
------------------------------
Original Message:
Sent: 07/07/26 04:54 PM
From: Michael Liu
Subject: how to intercept the URL input argument with luascript
Gary:
Thanks for your reply.
However, it does not satisfy my original requirement: intercept the input argument.
This is fundamental requirement for any policy sequence.
------------------------------
Michael Liu
------------------------------
Original Message:
Sent: 07/07/26 11:00 AM
From: GARY TU
Subject: how to intercept the URL input argument with luascript
Hi Micahel & Henry,
There is no pre-defined assembly context variables in NanoGateway, so context:get("request.querystring") would not work. But you can using set action to set the query parameters into context variable and using context:get() in LuaScript to get the data, for example
- set:
valueType: jsonata
variable:
name: queryParams
value: $queryParameters("request")
- luaScript:
source: |-
local params_array = context:get("queryParams")
local params = {}
for _, item in ipairs(params_array) do
for key, value in pairs(item) do
params[key] = value
end
end
console.info('request.params.city=' .. params.city)
------------------------------
------------------------------
Gary Tu
Software Developer, DataPower
------------------------------
------------------------------
Original Message:
Sent: 07/06/26 07:30 PM
From: Henry Collins
Subject: how to intercept the URL input argument with luascript
Thanks for the update.
From the information you've shared, it looks like the issue is specifically triggered by this line:
local query = context.get("request.querystring")
Without this line, the policy returns a 200 OK response. As soon as it's added, even though the query variable isn't used later. the API returns a 500 Internal Server Error.
This makes me think the issue is related to the context.get("request.querystring") call itself rather than the JSON construction or response handling.
------------------------------
Henry Collins
Web Developer
Dental Implant Cost Calculator
------------------------------
Original Message:
Sent: 07/06/26 07:20 PM
From: Michael Liu
Subject: how to intercept the URL input argument with luascript
Hi, Henry:
Thanks for your reply.
It was working with the following response:

Later on, once I add only first line:
local response = context:create_message("response")
response.status = 200
local request = context:get_message("request")
local clientId = request.headers["X-IBM-Client-Id"]
local clientSecret = request.headers["X-IBM-Client-Secret"]
response.headers["Content-Type"] = "application/json"
-- Build JSON object
local out = {
Weather = {
["X-IBM-Client-Id"] = clientId,
["X-IBM-Client-Secret"] = clientSecret,
Location = "Toronto",
Temperature = "25"
}
}
local query = context.get("request.querystring")
response.body:write(json.encode(out))
The result is as:

So the line as below breaks
local query = context.get("request.querystring")
------------------------------
Michael Liu
------------------------------
Original Message:
Sent: 07/06/26 06:35 PM
From: Henry Collins
Subject: how to intercept the URL input argument with luascript
You can get the query parameter from the request URL in Lua by using the API Connect context variables. For example, in a GatewayScript/Lua policy you can access the query string and parse it:
local query = context.get("request.querystring")
-- query will contain: city=Toronto
local city = string.match(query, "city=([^&]+)")
print(city)
If you are using IBM API Connect DataPower Gateway, you can also use the built-in urlopen/context variables depending on your policy type. Another option is to use a Set Variable or GatewayScript policy, which has easier URL parsing support. For multiple parameters or URL encoding, I'd recommend using GatewayScript with JavaScript's URLSearchParams instead of Lua, as it handles query strings more reliably.
------------------------------
Henry Collins
Web Developer
Dental Implant Cost Calculator
------------------------------