title: How to use a variable when returning response in policy definition?
body: <p>I'm configuring inbound policies in an instance of Azure API Management.</p>
  
  <p>First, I set a variable:</p>
  
  <pre><code>&lt;set-variable name="var1" value="" /&gt;
  </code></pre>
  
  <p>Then I send a request</p>
  
  <pre><code>&lt;send-request mode="new" response-variable-name="var1" timeout="20" ignore-error="false"&gt;
  </code></pre>
  
  <p>Which returns a JSON. When testing I get the following message in trace tab:</p>
  
  <blockquote>
    <p>GET request to '<a href="https://my-api.azure-api.net/api/data" rel="nofollow noreferrer">https://my-api.azure-api.net/api/data</a>' has been sent, result stored in 'var1' variable.</p>
  </blockquote>
  
  <p>I guess the send-request policy works and the result is stored in the variable.
  Then I want to return a response (still in inbound, I get 500 when trying to do it in outbound):</p>
  
  <pre><code>&lt;return-response response-variable-name="existing response variable"&gt;
      &lt;set-status code="200" reason="OK" /&gt;
      &lt;set-header name="Content-Type" exists-action="override"&gt;
          &lt;value&gt;application/json&lt;/value&gt;
      &lt;/set-header&gt;
      &lt;set-body&gt;
      {
          "success": true,
          "var1": context.Variables["var1"]
      }
      &lt;/set-body&gt;
  &lt;/return-response&gt;
  </code></pre>
  
  <p>My problem is it doesn't work... It just renders <code>context.Variables["var1"]</code>.</p>
  
  <p>And so does:</p>
  
  <ul>
  <li><code>@context.Variables["var1"]</code></li>
  <li><code>@{ context.Variables.GetValueOrDefault&lt;string&gt;("var1") }</code></li>
  <li><code>@context.Variables.GetValueOrDefault("var1")</code></li>
  </ul>
  
  <p>All of them are rendered as written, no value is being extracted.</p>
  
  <p>Edit: I also tried adding a placeholder string and then using </p>
  
  <pre><code>&lt;find-and-replace from="Placeholder" to="context.Variables.GetValueOrDefault("var1")" /&gt;
  </code></pre>
  
  <p>And try to place it in inbound and outbound alike. But this policy did not launch.</p>
  
  <p>It's a JSON object that I want to append to the response (small detail: in reality I have this issue with multiple variables).</p>
  
  <p>My question is: how can I add my declared variable to the response? </p>