How to get the value of target.url variable when target servers are used?

In my API proxy, I am using the Target Servers to connect to different backend server based on the environment. But when I extract the target.url variable in the target request post flow the value is always null. Any idea how to resolve this?

2 Likes

Hi @bibin_kurian, you may not be be access target.url when using target servers, why do you want to read it?

if you need just for logging, did you try request.url?

Thanks,

1 Like

@Mukundha Madhavan,

Thank you for your reply. Yes, I need target.url for logging purpose. I tried using request.url, it’s also null in the target endpoint request post flow.

ok i just did a quick test, for Target servers, the following variables are available in the ā€˜Target Response’ flow,

target.host

target.ip

request.path

using this I think you should be able to construct the full URL. Pls note it is at the ā€˜Target Response’ flow.

1 Like

It looks like these aren’t available in the Target Request Flow? It’s not really that big of a deal but I’m getting target.host populated on the ā€˜Target Response Flow’ but not the ā€˜Target Request Flow’

Is that correct?

Hi - when using target servers these values do not appear to be available in the target request flow.

This actually ā€œbrokeā€ the ā€œtemplateā€ that we have offered our internal users to work around some logging issues which I have brought up in the past.

At the moment we have just removed some of the data from the logs - but that wont be accepted as a long term solution.

To get the value of the target URL sent to the backend, even when using a TargetServer, you need access the request.url (not the target.url) variable in the TARGET RESPONSE PREFLOW (flow hook location).

I know it seems odd, but I’ve tested this and incorporated into my shared flows for GetLogValues and Log.

// When in TARGET RESPONSE PREFLOW
context.setVariable( 'logging.target.request.url', context.getVariable('request.url'));