How to access proxy flow variables in target flow?

Not applicable

I am extracting query parameters from calls sent to the Apigee proxy, and trying to place some of those variables within the target url. However, the AssignMessage policy in the target flow fails to resolve the variable. I even tried adding a `<VariablePrefix>apigee</VariablePrefix>` in the ExtractVariables policy in the proxy flow, but to no avail.

This was the corresponding response:

`{"fault":{"faultstring":"Unresolved variable : apigee.postalCode","detail":{"errorcode":"entities.UnresolvedVariable"}}}`

ExtractVariables policy in proxy pre-flow:

<ExtractVariables async="false" continueOnError="false" enabled="true" name="extract-params"> 
  <DisplayName>Extract Params</DisplayName> 
  <QueryParam name="postalCode">{postalCode}</QueryParam> 
  <QueryParam name="vin">{vin}</QueryParam> 
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> 
  <Source clearPayload="false">request</Source> 
  <VariablePrefix>apigee</VariablePrefix> 
</ExtractVariables>

AssignMessage policy in target pre-flow:

<AssignMessage name="set-credentials"> 
  <DisplayName>Set Credentials</DisplayName> 
  <Add> 
    <Headers> 
      <Header name="Authorization">Basic ...</Header> 
    </Headers> 
  </Add> 
  <AssignVariable> 
    <Name>target.url</Name> 
    <Value>https://base.url/{apigee.postalCode}/{apigee.vin}/values.json</Value> 
  </AssignVariable> 
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> 
  <AssignTo createNew="false" transport="http" type="request"/> 
</AssignMessage>
Solved Solved
0 2 1,767
1 ACCEPTED SOLUTION

Show your policy configuration, in its entirety.

Also describe specifically what you want to do. This is general: "trying to place some of those variables within the target url." Please be more specific. As specific as you can be.

To answer the question you posed in the title, you can access context variables from any place in the target flow. The variables like "request.queryparam.foo" will be accessible from within the target flow. You do not need a VariablePrefix. I am not sure what you're expecting to accomplish with that (because I haven't seen the rest of the policy).

EDIT:

This configuration:

<AssignMessage name="set-credentials"> 
   ...
  <AssignVariable> 
    <Name>target.url</Name> 
    <Value>https://base.url/{apigee.postalCode}/{apigee.vin}/values.json</Value> 
  </AssignVariable> 
</AssignMessage>

...won't work. It will not set target.url to a string while substituting the values of apigee.postalCode and apigee.vin. The Value element within AssignVariable accepts a plain value, not a message template. So the string assigned to target.url will be... exactly as it appears in your XML configuration.

There is a ticket in the backlog asking to allow the use of MessageTemplate within AssignVariable. b/65142528 .

But the enhancement has not been released yet.

Despite this, It sounds like you solved your problem in some other way. Glad to hear it.

View solution in original post

2 REPLIES 2

Show your policy configuration, in its entirety.

Also describe specifically what you want to do. This is general: "trying to place some of those variables within the target url." Please be more specific. As specific as you can be.

To answer the question you posed in the title, you can access context variables from any place in the target flow. The variables like "request.queryparam.foo" will be accessible from within the target flow. You do not need a VariablePrefix. I am not sure what you're expecting to accomplish with that (because I haven't seen the rest of the policy).

EDIT:

This configuration:

<AssignMessage name="set-credentials"> 
   ...
  <AssignVariable> 
    <Name>target.url</Name> 
    <Value>https://base.url/{apigee.postalCode}/{apigee.vin}/values.json</Value> 
  </AssignVariable> 
</AssignMessage>

...won't work. It will not set target.url to a string while substituting the values of apigee.postalCode and apigee.vin. The Value element within AssignVariable accepts a plain value, not a message template. So the string assigned to target.url will be... exactly as it appears in your XML configuration.

There is a ticket in the backlog asking to allow the use of MessageTemplate within AssignVariable. b/65142528 .

But the enhancement has not been released yet.

Despite this, It sounds like you solved your problem in some other way. Glad to hear it.

`request.queryparam.foo` worked! Thanks! I was earlier extracting query params into variables in proxy flow to save it, but it wasn't accessible in target flow. I wasn't aware that `request` can be accessed in target as well.