APIM to key vault request 400 bad request

Vikas Tiwari 766 Reputation points
2022-06-16T05:18:39.647+00:00

Hi,

I have APIM proxy which receives 400 bad request while fetching secrets from key vault. I have system assigned managed identity in APIM with reader role to key-vault, also no specials char in my secret following code using in my APIM proxy:

<inbound>  
        <base />  
        <send-request ignore-error="false" timeout="20" response-variable-name="keyResponse" mode="new">  
            <set-url>https://myvault.vault.azure.net/secrets/secretkey/</set-url>  
            <set-method>GET</set-method>  
            <authentication-managed-identity resource="https://vault.azure.net" />  
        </send-request>  
    </inbound>  

Thanks

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,126 questions
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,769 questions
0 comments No comments
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 21,471 Reputation points
    2022-06-16T09:44:09.313+00:00

    @Vikas Tiwari Thanks for reaching out, I see the request url is set incorrectly could you please change as below

    <send-request mode="new" response-variable-name="keyResponse" timeout="20" ignore-error="false">  
    <set-url>https://myvault.vault.azure.net/secrets/{Secret-name}/{Secret-version}?api-version=7.3</set-url>  
    <set-method>GET</set-method>  
    <authentication-managed-identity resource="https://vault.azure.net" />  
    </send-request>  
    

    Reference: https://learn.microsoft.com/en-us/rest/api/keyvault/secrets/get-secret/get-secret?WT.mc_id=AZ-MVP-5000570

    please let me know incase of further queries, I would be glad to assist you.

    To benefit the community find the right answers, please do mark the post which was helpful by clicking on Accept Answer’ & ‘Up-Vote’.


1 additional answer

Sort by: Most helpful
  1. Jaliya Udagedara 2,731 Reputation points MVP
    2022-06-16T08:08:44.747+00:00

    Shouldn't the <set-url> be,

    <set-url>https://myvault.vault.azure.net/secrets/{secret-name}?api-version=7.3</set-url>  
    

    Reference: Get Secret - Get Secret