Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to dynamically set target URL?

Not applicable

Hi, My requirement is to create a new general purpose API proxy that will dynamically set the target URL and therefore capable of forwarding payloads to different URLs of the same or different origin systems.

  • Authentication: OAuth
  • Target endpoint: dynamic, grammatically obtained from "s_url" from within the payload.
Solved Solved
1 7 14.4K
1 ACCEPTED SOLUTION

yes, the correct use of the AssignMessage policy in this case is:

<AssignMessage name="Assign-Message-1">
    <AssignVariable>
        <Name>target.url</Name>
        <!-- <Value>{apigee.eventName}</Value>  NO-->
        <Ref>apigee.eventName</Ref>  <!-- YES -->
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

The Value element is used to set a specific value. The text of the Value element is not interpreted as a Message Template. (Wrapping variable names in curlies inside the Value element... does nothing! Though there is an outstanding feature request to allow something like this. (** See below for an update on this))

Be aware: Writing the target.url is effective only when executed in the request flow of the target endpoint.


EDIT 2021 July - There has been, for some time now, an additional option within the AssignVariable element, to allow message templates. It is the Template element. it's pretty simple to use. It looks like this:

<AssignMessage name="Assign-Message-1">
    <AssignVariable>
        <Name>target.url</Name>
        <!-- <Value>{apigee.eventName}</Value> does nothing -->
        <Template>{foo} fixed text {bar}</Template> 
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

Readers may want to check the documentation for precedence and etc.

View solution in original post

7 REPLIES 7