Kong Request Transformer and Optional Query Parameters

We have a use case whereby we have optional query parameters in our API. For example, for one of our GET ‘list’ endpoints we’d like a query parameter named ‘skip’ that allows us to paginate through large datasets. We have something like the below in our request transformer:

- ‘skip:$(query_params[“skip”])’

However, from what I can see reading the documentation (Request Transformer plugin | Kong Docs) and looking online, it looks like there’s no way to conditionally add the optional query parameter to the request body (i.e. to maintain that optional notion) - have I got that right? As things stand, if ‘skip’ is not provided, it is still added to the request body but as an empty string (’’). This therefore means we have to add server-side logic to each back-end service that could receive such an optional query parameter to cater for the fact they could be empty (which is not ideal) - rather than the transformer simply not adding them if they’re not needed.

Any ideas if what I’m after is possible / any other workarounds?

I believe advanced templates is what you are looking for

You can write lua code to add skip optionally.

Thanks, I considered that but was unsure looking at the docs how you’d remove the body key if the parameter you were looking for wasn’t present? It looked from the docs like you can dynamically change the value but not optionally add the key in the first place (i.e. the key must always be static)?