简体   繁体   中英

Get route parameters in Azure API Management Inboud policy section

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM