營利限制檢查政策

查看 Apigee Edge 說明文件。
前往 Apigee X說明文件
資訊

總覽

營利限制政策可讓你對發出的 API 呼叫強制執行營利限制 。

以下列舉一些觸發政策的情況:

  • 如果存取營利 API 的應用程式開發人員尚未購買 相關的 API 產品
  • 開發人員帳戶的餘額不足。
  • 開發人員的交易量已超出上限。

如要瞭解如何將政策附加至 API Proxy,請參閱 對 API Proxy 強制執行營利限制

<MonetizationLimitsCheck> 個元素

指定 MonetizeLimitsCheck 政策。

預設值 不適用
是否必填? 必填
類型 複雜類型
父項元素
子元素 <DisplayName>
<FaultResponse>
<IgnoreUnresolvedVariables>
<Variables>

下表概略說明 <MonetizationLimitsCheck> 的子項元素:

子元素 必填與否 說明
<DisplayName> 選用 政策的自訂名稱。
<FaultResponse> 選用 指定在出現以下情況時,傳回給提出要求用戶端的回應訊息: 錯誤。
<IgnoreUnresolvedVariables> 選用 判斷遇到未解析的變數時,處理程序是否停止。
<Variables> 選用 指定要檢查營利限制的流程變數。

<MonetizationLimitsCheck> 元素使用下列語法:

語法

<?xml version="1.0" encoding="UTF-8"?>
<MonetizationLimitsCheck async="false" continueOnError="false" enabled="true" name="POLICY_NAME">
    <DisplayName>DISPLAY_NAME</DisplayName>
    <IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>
    <Variables>
        <Product>VARIABLE_NAME</Product>
    </Variables>
    <FaultResponse>
        <Set>
            <Payload contentType="text/xml">
                <error>
                    <messages>
                        <message>MESSAGE_TEXT</message>
                        <message>MESSAGE_TEXT</message>
                    </messages>
                </error>
            </Payload>
            <StatusCode>HTTP_STATUS</StatusCode>
            <ReasonPhrase>REASON_TEXT</ReasonPhrase>
        </Set>
    </FaultResponse>
</MonetizationLimitsCheck>

範例

營利限制檢查政策定義範例如下:

<?xml version="1.0" encoding="UTF-8"?>
<MonetizationLimitsCheck async="false" continueOnError="false" enabled="true" name="Monetization-Limits-Check">
    <DisplayName>Monetization Limits Check</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Variables>
        <Product>myproductvar.name</Product>
    </Variables>
	<FaultResponse>
	        <Set>
	            <Payload contentType="text/xml">
	                <error>
	                    <messages>
	                        <message>Developer has reached usage quota</message>
	                        <message>Is Developer Suspended - {monetizationLimits.isDeveloperSuspended} </message>
	                    </messages>
	                </error>
	            </Payload>
	            <StatusCode>403</StatusCode>
	            <ReasonPhrase>Forbidden</ReasonPhrase>
	        </Set>
	</FaultResponse>
 </MonetizationLimitsCheck>

This element has the following attributes that are common to all policies:

Attribute Default Required? Description
name N/A Required

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

continueOnError false Optional Set to "false" to return an error when a policy fails. This is expected behavior for most policies. Set to "true" to have flow execution continue even after a policy fails.
enabled true Optional Set to "true" to enforce the policy. Set to "false" to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.
async   false Deprecated This attribute is deprecated.

子元素參照

本節將說明 <MonetizationLimitsCheck> 的子元素。

<DisplayName>

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, more natural-sounding name.

The <DisplayName> element is common to all policies.

Default Value n/a
Required? Optional. If you omit <DisplayName>, the value of the policy's name attribute is used
Type String
Parent Element <PolicyElement>
Child Elements None

The <DisplayName> element uses the following syntax:

Syntax

<PolicyElement>
  <DisplayName>policy_display_name</DisplayName>
  ...
</PolicyElement>

Example

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

The <DisplayName> element has no attributes or child elements.

<IgnoreUnresolvedVariables>

決定當 Apigee 遇到未解析的變數時,是否要停止處理政策。

預設值
是否必填? 選用
類型 布林值
父項元素 <MonetizationLimitsCheck>
子元素

如要忽略未解析的變數並繼續處理,請將值設為 true; 否則為 false。預設值為 true

<IgnoreUnresolvedVariables> 設為 true 與設定 <MonetizationLimitsCheck> 元素的 continueOnErrortrue。如果將 continueOnError 設為 true,Apigee 就不會 只有變數錯誤外計入所有錯誤

<IgnoreUnresolvedVariables> 元素使用下列語法:

語法

<IgnoreUnresolvedVariables>[true|false]</IgnoreUnresolvedVariables>

範例

下列範例會將 <IgnoreUnresolvedVariables> 設為 false

<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

<Variables>

指定要從哪個流程變數擷取 實體或資源名稱。

您只能在 <Variables> 元素中指定 <Product> 元素。Apigee 儲存空間 從 <Product> 元素中指定的流程變數中取得 API 產品名稱。如果發生以下情況: 未指定 <Variables> 元素,Apigee 預設會從 apiproduct.name 結構定義變數。透過使用 API 產品名稱,Apigee 會取得 然後檢查營利限制

預設值 不適用
是否必填? 選用
類型 複雜類型
父項元素 <MonetizationLimitsCheck>
子元素 <Product>

<Variables> 元素使用下列語法:

語法

<Variables>
    <Product>VARIABLE_NAME</Product>
</Variables>

範例

以下範例會從 myproductvar.name 自訂流程變數取得 API 產品名稱 都會顯示在 API Proxy 流程中

<Variables>
    <Product>myproductvar.name</Product>
</Variables>

您可以使用 AssignMessageJavaScript 等政策設定自訂變數變數。

<Product>

指定具有 API 產品名稱的變數。

預設值 不適用
是否必填? 選用
類型 字串
父項元素 <Variables>
子元素

<Product> 元素使用下列語法:

語法

<Product>VARIABLE_NAME</Product>

範例

以下範例會從 myproductvar.name 自訂流程變數取得 API 產品名稱 都會顯示在 API Proxy 流程中

<Product>myproductvar.name</Product>

您可以使用 AssignMessageJavaScript 等政策設定自訂變數變數。

<FaultResponse>

定義在發生故障時,傳回給要求用戶端的回應訊息。 您可以自訂回應內容 接收自訂訊息如要進一步瞭解 元素及其所有子元素,請參閱 FaultResponse 一節。

流程變數

如果設定了 <MonetizationLimitsCheck> 元素的 ContinueOnError 屬性為 true,不會提出任何錯誤。在此情況下, 流程變數、mint.limitsViolatedmint.isDeveloperSuspended 和 系統會自動設定 mint.limitsPolicyError。這些變數可用於 視需要執行進一步的例外狀況處理