Skip to content

Latest commit

 

History

History
66 lines (44 loc) · 2.38 KB

set-status-policy.md

File metadata and controls

66 lines (44 loc) · 2.38 KB
title description services author ms.service ms.topic ms.date ms.author
Azure API Management policy reference - set-status | Microsoft Docs
Reference for the set-status policy available for use in Azure API Management. Provides policy usage, settings, and examples.
api-management
dlepow
azure-api-management
article
07/23/2024
danlep

Set status code

[!INCLUDE api-management-availability-all-tiers]

The set-status policy sets the HTTP status code to the specified value.

[!INCLUDE api-management-policy-generic-alert]

Policy statement

<set-status code="HTTP status code" reason="description"/>

Attributes

Attribute Description Required Default
code Integer. The HTTP status code to return. Policy expressions are allowed. Yes N/A
reason String. A description of the reason for returning the status code. Policy expressions are allowed. Yes N/A

Usage

Example

This example shows how to return a 401 response if the authorization token is invalid. For more information, see Using external services from the Azure API Management service.

<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>

Related policies

[!INCLUDE api-management-policy-ref-next-steps]