Get route parameters in Azure API Management Inboud policy section
Asked Answered
W

1

5

I have a URL with template parameters.

https://test.azure-api.net/HelperFunction/{siteId}/lots/InventoryItem/{itemId}
https://test.azure-api.net/HelperFunction/122/lots/InventoryItem/12

I wanted to read the template/path parameters in inbound policy section.

I am trying as below. But it will only fetch the query string parameters. I wanted to get the path parameters.

 <inbound>
        <set-body>@{
                JObject transBody = new JObject();
                transBody.Add("Arguments", 
                new JObject
                {
                    {"method", context.Request.Method},
                    {"parameters", context.Request.Url.QueryString},
                });

                //Add all json properties as arg
                transBody.Add("UriPath", context.Request.Url.Path);
                return transBody.ToString();
            }</set-body>
        <base />
 </inbound>

My requirement would be to read route parameters as

"siteId" : 122,
"itemId" : 12

Any help would be appreciated.

Wrist answered 2/4, 2020 at 9:47 Comment(0)
N
7

context.Request.MatchedParameters["siteId"] and context.Request.MatchedParameters["itemId"]

Rest of context variable can be found here: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables

Nygaard answered 4/4, 2020 at 4:58 Comment(1)
I need the whole collection. I don't know what parameters will be in request. I need to fetch dynamically all the request path parameters.Wrist

© 2022 - 2024 — McMap. All rights reserved.