How to call/retrieve value from Azure app config through APIM policy

Amit Srivastava 60 Reputation points
2023-03-13T09:50:43.4633333+00:00

Hi Team, need help, I want to make call from APIM policy(c# code) to Azure app config to retrieve value against a key. But I am unable to figure out how to achieve this. Can you please help me. Thanks in advance

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,172 questions
Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
237 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,336 Reputation points
    2023-03-13T22:48:22.9833333+00:00

    Amit Srivastava Thank you for posting your question in Microsoft Q&A.

    Here are the steps you can follow to achieve this:

    1. Enable System-assigned Managed Identity for your APIM instance as described Use managed identities in Azure API Management.
    2. Assign Azure App Configuration Data Reader role for the managed identity as per doc: AD Authentication
    3. Then write a custom policy to send request to Azure App Configuration Rest API (https://learn.microsoft.com/en-us/azure/azure-app-configuration/rest-api-key-value#get-key-value) to get the key value and use authentication-managed-identity policy to generate authorization token. Refer sample code snippet below: (replace <app-config-name> and testkeyname with actual value)
       <send-request mode="new" timeout="20" ignore-error="false" response-variable-name="tokenstate">
                   <set-url>@("https://<app-config-name>.azconfig.io/kv/testkeyname?api-version=1.0")</set-url>
                   <set-method>GET</set-method>
                   <authentication-managed-identity resource="https://azconfig.io" ignore-error="false" />
               </send-request>
               <set-variable name="keyValue" value="@(((IResponse)context.Variables["tokenstate"]).Body.As<JObject>()["value"])" />
    

    Note, the above code snippet is a sample policy for your reference, and you can customize it based on your need. If you face any issues, let me know. I hope this helps with your question.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.