What are the available properties in IResponse?

Kumpala, Deepak DEEKU 1 Reputation point
2023-03-29T08:31:57.2066667+00:00

I have come across below namespace

Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.PipelineResponse

Based on this, I am adding below policy in my Azure APIM

 <return-response>
   <set-status code="403" reason="error" />
    <set-body template="none">@(((IResponse)context.Variables["Value"]).Body.As&lt;JObject&gt;(preserveContent: true).ToString())</set-body>
    </return-response>

I am trying to retrieve Value data from Variables as shown above.

I am getting below response which does not clearly tell what is the issue. I want more information. So in which IResponse property I will get more data?

User's image

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,075 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,848 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,311 Reputation points
    2023-03-31T13:33:45.18+00:00

    Kumpala, Deepak DEEKU Thank you for posting your question in Microsoft Q&A. Context Variable is set using set-variable policy (reference: Set variable) via expression or string literal and then available in every policy expression via context. Variables as IReadOnlyDictionary<string, object>. So, you need to set variable Value before accessing it and based on the exception, this key was not set in the policy and hence you got the exception above. Please check out the reference docs on how to set and retrieve the variables. If you are setting this value in your policy, please share the full code snippet.

    For your second question, it looks like you are trying to retrieve IResponse object, and you can use context.Response like context.Response.Body.As<JObject>(preserveContent: true) and available properties are described as below:

    User's image

    I hope this helps with your question and let me know if you have any other questions.

    0 comments No comments

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.