How to create dynamic URL at runtime?

Hi,

we have URL like this https://{domain name}/API/atom_dictionaries/{app GUID}/atoms.json?auth_token={access Token}, How can we i create dynamic in Apigee?

0 2 365
2 REPLIES 2

I'm going to assume when you say

How can we i create dynamic in Apigee?

...that you mean, how can you create a dynamic URL, that Apigee should use for the target, at runtime within the execution of an API request?

You can do that with an AssignMessage policy. The pre-requisite is that each of the "replaceable items" is available in a context variable within the Apigee proxy. How that information gets into the context variable, is ... irrelevant. For example, you could have your API proxy do a "lookup" of the domain name, based on the inbound API credential, by calling out to an external service. Or, you could attach the domain name and App GUID to the "Developer App" within Apigee, as a custom attribute. Then, after verifying app credentials (like an API key or token), the value of that custom attribute would be loaded directly into a context variable. Another option is to use a weighted random selection from a list. The point is, there are different ways of getting the various data items into a set of context variables. After you have that, then using AssignMessage to build the URL is really easy. It looks like this:

 

<AssignMessage name='AM-Assign-Target-URL'>
  <AssignVariable>
    <Name>target.url</Name>
    <Template>https://{domainname}/API/atom_dictionaries/{appGUID}/atoms.json?auth_token={upstreamAccessToken}</Template>
  </AssignVariable>
</AssignMessage>

 

The key here is

  • you need to assign to target.url
  • Use the "Template" element
  • refer to the context variables with curly braces
  • Attach that policy to the Target Request flow.

If you do this, you will dynamically override the URL specified in the HTTPTargetConnection .

Thanks a lot for detailed explanation.