policy expression within send-request set-url

Matthew J Van Auwelaer 21 Reputation points
2022-10-27T15:47:22.3+00:00

Per https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-send-request, I am attempting to call an external service that is not the backend API itself.

When attempting to configure a policy like this:

<send-request mode="new" response-variable-name="externalServiceResponse">  
  <set-url>https://@(context.Variables.GetValueOrDefault<string>("hostname"))/some/api</set-url>  

I get the error:
Error in element 'send-request' on line 7, column 6: Value is not a valid absolute URL

Is there any way to use a policy expression within send-request's set-url? Is there any other alternative to a hardcoded URL value? This would seem critical to using different external service URLs in different deployment environments (dev, QA, production).

Thanks

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

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2022-10-27T18:06:34.76+00:00

    @Matthew J Van Auwelaer Thank you for reaching out to Microsoft Q&A. For your scenario, use the policy snippet like below and check the sample evaluation on the same:

    <set-variable name="hostname" value="contoso.com" />  
    <send-request mode="new" response-variable-name="externalServiceResponse">  
                    <set-url>@($"https://{context.Variables.GetValueOrDefault<string>("hostname")}/some/api")</set-url>  
                    <set-method>GET</set-method>  
                    <set-body />  
    </send-request>  
    

    254814-image.png

    Alternatively, you can explore Named value and define policy like below:
    <send-request mode="new" response-variable-name="externalServiceResponse">
    <set-url>@($"https://{{external-url-test}}/some/api")</set-url>
    <set-method>GET</set-method>
    <set-body />
    </send-request>

    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.

    1 person found this answer helpful.
    0 comments No comments

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.