title: Service callout with dynamic host name
body: <p>I have a proxy in Apigee that uses a service callout to another proxy in the same environment. I would like to set the URL host for the callout to match the host of the initial request.</p>
  
  <p>For example, if a request is made in the dev environment to:</p>
  
  <pre><code>https://example-dev.apigee.com/awesome-proxy
  </code></pre>
  
  <p>I need to make a call to:</p>
  
  <pre><code>https://example-dev.apigee.com/support-proxy
  </code></pre>
  
  <p>In a test environment the first call is to:</p>
  
  <pre><code>https://example-test.apigee.com/awesome-proxy
  </code></pre>
  
  <p>The support call needs to go to:</p>
  
  <pre><code>https://example-test.apigee.com/support-proxy
  </code></pre>
  
  <p>Here is how I would like to define the service callout policy:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ServiceCallout async="false" continueOnError="false" enabled="true" name="serviceCallout"&gt;
      &lt;DisplayName&gt;serviceCallout&lt;/DisplayName&gt;
      &lt;FaultRules/&gt;
      &lt;Properties/&gt;
      &lt;Request clearPayload="true" variable="example.request"&gt;
          &lt;IgnoreUnresolvedVariables&gt;false&lt;/IgnoreUnresolvedVariables&gt;
      &lt;/Request&gt;
      &lt;Response&gt;example.response&lt;/Response&gt;
      &lt;HTTPTargetConnection&gt;
          &lt;Properties/&gt;
          &lt;URL&gt;{client.host}/support-proxy&lt;/URL&gt;
      &lt;/HTTPTargetConnection&gt;
  &lt;/ServiceCallout&gt;
  </code></pre>
  
  <p>This will not save and complains about no protocol. The help indicates that this must be hard coded:</p>
  
  <pre><code>&lt;HTTPTargetConnection&gt;/&lt;URL&gt; element
  The URL to the service being called. While the hostname portion of URL must be hard-coded, you can supply the remainder of the URL dynamically with a variable.
  </code></pre>
  
  <p>I found a variable to define the URL of a service callout:</p>
  
  <pre><code>servicecallout.{policy-name}.target.url
  </code></pre>
  
  <p>I attempted to use an assign message policy to dynamically set the variable, as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;AssignMessage async="false" continueOnError="false" enabled="true" name="assignCalloutURL"&gt;
      &lt;DisplayName&gt;assignCalloutURL&lt;/DisplayName&gt;
      &lt;FaultRules/&gt;
      &lt;Properties/&gt;
      &lt;AssignVariable&gt;
          &lt;Name&gt;servicecallout.serviceCallout.target.url&lt;/Name&gt;
          &lt;Value&gt;{client.host}&lt;/Value&gt;
          &lt;Ref/&gt;
      &lt;/AssignVariable&gt;
      &lt;IgnoreUnresolvedVariables&gt;true&lt;/IgnoreUnresolvedVariables&gt;
      &lt;AssignTo createNew="false" transport="http" type="request"/&gt;
  &lt;/AssignMessage&gt;
  </code></pre>
  
  <p>This sets the URL to the literal text <code>{client.host}</code></p>
  
  <p>I have used the assign message policy in a similar fashion for other purposes and it actually resolves the variable listed. I'm not sure what's happening here. </p>