Skip to Content
Technical Articles
Author's profile photo Jeremy Ma

APIM Dynamic Routing w. Payload or Header

What: There is good blog already on how to deploy Dynamic Routing by Raghavendra, this blog is about how to pass the routing logic via payload or header instead of context path.

Why:  Having sender to code logic to context path is not always possible and you may want to keep the existing URI context path consistent and simple


  1. Should familiarized the standard option as stated above blog
  2. In Mediation Policies, Add the Extract Variable policy
  3. Define the numerous target end points in APITargetEndPoint
  4. Deploy and Test

In the below example where I show routing to various wiki of countries base on payload country to direct wiki


2. Extract Variable from payload

<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->
<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns=''>
	<!-- the source variable which should be parsed -->
	<!-- Specifies the XML-formatted message from which the value of the variable will be extracted -->
      <Variable name="country">


3. Define Various Target Endpoints


Unzip of APIProxy with TargeEndPoint Folder

targetf example file for France

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndPoint xmlns="">

4. Deploy and review the mapping


Import Policy and View ProxyEndpoint

Inspect the variable:


Debug of the APIM Steps – Extract variable


Notice below POST call matching Step2 above of Condition String


Testing with Postman



Acknowledge:  Thanks to my colleague Vinayak Adkoli to provided the first POC;

Additional references


Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Michael-Peter Liermann
      Michael-Peter Liermann

      I've already used this approach. There is one very big drawback, however. Target policies that are edited in the UI are only changed for the default target endpoint, not for the other target endpoints.