Can we use set-query-parameter policy inside send-request policy? -No

Several times you come across a situation where you should use send-request policy to make use of an external service to perform complex processing functions and return data to the API management service that can be used for further policy processing.

The send-request policy looks like this:

<send-request mode="new" response-variable-name="tokenstate" timeout="20" ignore-error="true">
<set-header name="Authorization" exists-action="override">
<value>basic dXNlcm5hbWU6cGFzc3dvcmQ=</value>
<set-header name="Content-Type" exists-action="override">

Now if you want to use query string parameters in the URL under set-url policy used above using set-query-parameter policy then it is not allowed and you will not be able to even save your configured policy. Generally, we get confused and try to make use of this policy inside send-request policy but set-query-parameter policy is used to add, replace value of, or deletes request query string parameter. It Can be used to pass query parameters expected by the backend service which are optional or never present in the request according to this link
Now the question is how to pass query string parameters? It’s very simple and logical, we can make use of APIM variables in this scenario.

Firstly, setting the variables with some values:

<set-variable name="fromDate" value="@(context.Request.Url.Query["fromDate"].Last())">
<set-variable name="toDate" value="@(context.Request.Url.Query["toDate"].Last())">

And secondly making use of these variables inside send-request policy:

<send-request mode="new" response-variable-name="revenuedata" timeout="20" ignore-error="true">

Refer this link for more details

Please let me know your queries.

Happy Coding!

Comments (0)

Skip to main content