0

I have added an external API to API management. The API always returns 200 response even for bad requests. The response has a property called status which says if the response is ok or if it is a bad request

Can I configure API Management to return a response code based on the 'status' property in this response? Is so how do I do that?

1 Answer 1

2

You can use set-status policy (to set the HTTP status code) together with choose policy (to check your property value). Check set-status documentation for details.

The following example from Microsoft documentation shows how to return a 401 response if the authorization token is invalid.

<choose>
  <when condition="@((bool)((IResponse)context.Variables["tokenstate"]).Body.As<JObject>()["active"] == false)">
    <return-response response-variable-name="existing response variable">
      <set-status code="401" reason="Unauthorized" />
      <set-header name="WWW-Authenticate" exists-action="override">
        <value>Bearer error="invalid_token"</value>
      </set-header>
    </return-response>
  </when>
</choose>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.