Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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:



https://microsoft-apiappec990ad4c76641c6aea22f566efc5a4e.azurewebsites.net/introspection
POST

basic dXNlcm5hbWU6cGFzc3dvcmQ=


application/x-www-form-urlencoded

@($"token={(string)context.Variables["token"]}")

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 https://msdn.microsoft.com/library/azure/7406a8ce-5f9c-4fae-9b0f-e574befb2ee9#SetQueryStringParameter
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:


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


@($"https://accounting.acme.com/salesdata?from={(string)context.Variables["fromDate"]}&to={(string)context.Variables["fromDate"]}")"
GET

Refer this link for more details https://github.com/Microsoft/azure-docs/blob/master/articles/api-management/api-management-sample-send-request.md

Please let me know your queries.

Happy Coding!

Share the post

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

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×