Azure APIM - how to invoke rest API with OData filters?

Henrique Carvalho 1 Reputation point
2022-11-10T01:03:42.57+00:00

I created a manual API in APIM
Need the API to have an operation which invokes a rest API with OData filering
e.g: https://graph.microsoft.com/v1.0/users?$filter=mail eq 'MeganB@M365x214355.onmicrosoft.com'

258904-screenshot-2022-11-10-at-004327.png258905-screenshot-2022-11-10-at-004045.png

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,882 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,256 Reputation points
    2022-11-10T16:02:10.913+00:00

    @Henrique Carvalho Thank you for reaching out to Microsoft Q&A. Based on the above statement, you are looking to call backend API (Graph) with query parameters (OData filters). This depends on how you want to set up APIM call.

    Use parameterized operation to add a query parameter with or without default value as shown below and this way you can call APIM call with needed filters. Refer Add and test a parameterized operation for more info.

    259087-image.png

    Note, parameters are url-encoded and hence you need to use set-query-parameter policy (docs) to decode before sending to backend like below.

    <set-query-parameter name="$filter" exists-action="override">  
                <value>@(System.Net.WebUtility.UrlDecode(context.Request.Url.Query["$filter"][0]))</value>  
            </set-query-parameter>  
    

    Also, set-query-parameter can be used to transform the request and here is the sample blog on the same. I hope this answers your question and feel free to add a comment if you have any other questions. We would be happy to assist you. Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community.

    0 comments No comments