Dynamic pass hostname in URL

How can we pass a host variable to target URL? This variable will be different across the environments & tried using KVM but it doesn't get populated. It gets extracted but doesn't get assigned..tried in target pre flow

eg: apiHost-> apigee-test.apigee.net

<HTTPTargetConnection>
  <URL>https://{apiHost}/v1/token</URL>  </HTTPTargetConnection>

Error:

error.class com.apigee.errors.http.server.ServiceUnavailableException
error.cause Host not reachable

Thanks

0 4 987
4 REPLIES 4

Hi @vinay, If you are Service Callout policy than this should work as long as you use the KVM extraction policy before that to extract the KVM value. If you are trying to do that in the Target Endpoint that it will have a problem. The proper way of doing this is first configure your target server in Admin->Environment->Target Servers, make sure that you configure using the name for each Environment configurations, but pointing to your correspondent target endpoint. After you configured your target server variable for each of your environment, you can use the LoadBalancer property to point to your target server variable. This way if you call test api proxy it will point to a test target endpoint and when calling prod proxy endpoint you are connecting to the prod target endpoint. For more info see https://docs.apigee.com/api-services/content/load-balancing-across-backend-servers

Thanks for the detail but looking for simple replacement of endpoint for host in HTTPTargetConnection at URL.We use LB VIP and not individual servers.

Is there a better way to do? We are not using service callout.

I see, you can't use the Apigee load balancing instead? I am not sure if there's a simple way to do this if you are using a target endpoint, unless you can change it to use Service Callout instead.