1. Create usage alert and set up thresholds
Use a valid access token and make a POST call to the/v1/commerce/billing/subscriptions/{external_subscription_id}/alerts endpoint with all required request parameters.
Path parameter: external_subscription_id is the external_id you provided when you created the subscription.
On successful alert creation, the PayPal server returns an alert ID.
Request parameters
| Parameter name | Description |
|---|---|
typeRequired, string | Type of alert to create. Possible values: CURRENT_USAGE_AMOUNT: Alert on total usage amount for the current billing cycleMETRIC_CURRENT_USAGE_AMOUNT: Alert on monetary usage of a specific metric for the current billing cycleMETRIC_CURRENT_USAGE_UNITS: Alert on units consumed for a specific metric in the current billing cycleLIFETIME_USAGE_AMOUNT: Alert on total usage amount across the entire subscription duration |
codeRequired, string | Unique code to identify the alert. |
metric_codestring | Identifier of the metric associated with the alert. Use the code you provided when you created the metric. Required only for metric-based alert types (METRIC_CURRENT_USAGE_AMOUNT and METRIC_CURRENT_USAGE_UNITS). |
namestring | Name of the alert. |
thresholds[]Required, array | List of thresholds that trigger the alert. At least one threshold is required. Includes both one-time and recurring thresholds. |
thresholds[].codestring | User-defined identifier for the threshold. Used to distinguish between different thresholds (for example, warn, hard, recurring). |
thresholds[].valueRequired when thresholds[] provided, string | Value that should trigger this alert. Must be a positive numeric string that can include a decimal point. |
thresholds[].recurringboolean | Specifies whether the threshold is recurring. When true, alerts are triggered every time the usage exceeds the last non-recurring threshold by this threshold’s value. Only one recurring threshold is permitted per alert. |
Response parameters
This section documents only the response parameters relevant for the next step. For the exhaustive list of response fields, see API reference.
| Parameter name | Description and further action |
|---|---|
idstring | Unique identifier for the alert. Use this id in future operations, such as when managing or referencing the alert. |
external_subscription_idstring | Unique identifier of the subscription linked to the alert. Use this external_subscription_id to fetch subscription details or list all alerts for a subscription. |
2. Use webhooks to monitor threshold breaches
- Subscribe to the
USAGE-BILLING.SUBSCRIPTION-ALERT.TRIGGEREDevent through one of the following means:- PayPal developer account: Log in to your account, go to App details page > Features > Webhooks, and subscribe to the webhook event.
- Webhooks management API.
- In your server-side app code, define a webhook handler that:
- Listens to the webhook event.
- Confirms receipt of the webhook event to PayPal.
- Verifies the source of the event notification.
- Parses the webhook payload received from PayPal - it includes the alert ID, subscription ID, alert type, metric code, current value, crossed thresholds, and trigger time. See the webhook payload sample for details.
- Uses the parsed data to notify users, enforce limits, or automate business logic.
You can also subscribe to webhooks for wallet, invoice, credit note, and subscription lifecycle events. For the complete list of webhook events and sample payloads, see Webhooks reference.