为费率方案设置限制通知

您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档
信息

您可以通过电子邮件通知开发者,让他们购买的按用量带动或套装价目表方案接近或达到特定上限。例如,如果开发者购买一个捆绑包中包含 1,000 个调用的音量转移方案,您可以通知他们调用次数达到 800 次(使用率为 80%)或 API 调用支出达到 $500 时。

如需使用 API 为费率方案设置限制通知,请执行以下步骤:

  1. 自定义用于通知开发者的通知模板
  2. 配置通知条件和操作

自定义通知模板

以下示例说明了如何自定义用于通知开发者的通知模板。如需了解详情,请参阅使用 API 管理通知模板

$ curl -H "Content-Type: application/json " -X POST -d \    
'{
    "name": "RATE_PLAN_LIMIT_TEMPLATE",
    "subject": "Nearing your rate plan limit",
    "htmlImage": "<p>Hi ${developer.name} - Wanted to let you know that you have used 800 API calls from your ${ratePlan.displayName} rate plan, which started on ${ratePlan.startDate} under the ${ratePlan.monetizationPackage.displayName} package and ${ratePlan.monetizationPackage.products.displayName} product. Just a friendly reminder that your API calls will be charged double after you cross 1000 calls. Thanks for using the API!</p>",
    "source": "Postman API call"
    }' \
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/notification-email-templates" \
    -u email:password

配置通知条件和操作

按照使用 API 配置通知条件和操作中的说明,使用 API 配置通知条件和操作。

如需触发费率方案限制的通知,请设置以下属性:

  • RATEPLAN - 要发送的通知的类型。
  • PUBLISHED - 将此属性设为 TRUE 可触发已发布的费率方案的通知。

然后,指定以下属性之一:

  • Transactions - 交易次数。例如,在开发者完成 800 笔交易时通知他们。必须是整数值,并且只能使用 > 和 = 运算符。
  • FeeExposure - 交易累计的美元或积分金额。必须是整数值,且只能使用 > 和 = 运算符。FeeExposure 不包括设置费、定期费或终止费金额。例如,在 API 交易费用达到 $500 时通知开发者。FeeExposure 的计算方法因税率而异。

当事务数量达到 800 时,以下载荷会触发电子邮件通知:

$ curl -H "Content-Type:application/json" -X POST -d \
    '{
    "notificationCondition": [
      {
        "attribute": "RATEPLAN",
        "value": "{RATE_PLAN_ID}"
      },
      {
        "attribute": "PUBLISHED",
        "value": "TRUE"
      },
      {
        "attribute": "Transactions",
        "value": "= 800"
      }     
    ],
   "actions": [{
          "actionAttribute": "DEV_ID",
          "value": "ANY",
          "templateId": "{EMAIL_TEMPLATE_ID}"
        }]
  }' \
"https://api.enterprise.apigee.com/v1/mint/organizations/{org_name}/notification-conditions" \
    -u email:password