Limited Release
An event is an action your customer takes while using your product or service. For example, making an API call, uploading a file, or using storage space are all events. Each event uses some amount of a metric. This metric usage affects your billing. You need to record each event’s metric usage with PayPal. PayPal uses this data to track usage and calculate charges. This process of recording usage is called metering.
An event connects the following entities:
- The metric that measures what you charge for (API calls, storage GB).
- The customer’s subscription that determines their pricing plan and billing cycle.
- The actual metric usage that an event consumes. PayPal aggregates this data to calculate charges.
Prerequisites
- Create and set up all metrics that define how events are aggregated for billing.
- Register the customers to whom you want to track usage events.
- Create subscriptions that link customers to your pricing plans.
1. Send usage events to PayPal
You can send usage events using one of the following methods:Send multiple events
Use a valid access token and make a POST call to the/v1/commerce/billing/events endpoint. Include the following parameters:
| Parameter | Action |
|---|---|
transaction_idRequired, string | Set a unique identifier for this event. Ensure values are unique across all events. |
metric_codeRequired, string | Set to the code returned when you created the metric. |
external_subscription_idRequired, string | Set to the external_id returned when you created the subscription. |
timestampstring | Set the ISO 8601 timestamp when the event occurred. If not provided, PayPal uses the current time. |
propertiesRequired for SUM, MAX, COUNT_DISTINCT, and LATEST aggregation types, object | Provide key-value pairs for event properties and usage amounts. The property key (for example, gb or minutes) must match the aggregation_field from your metric configuration. |
201 Created response with the event ID.
Send a batch of events
Use a valid access token and make a POST call to the/v1/commerce/billing/events/batch endpoint. You can send up to 100 events in a single batch request. Include the following parameters:
| Parameter | Action |
|---|---|
eventsRequired, array | Provide an array of event objects (up to 100 events per batch). |
events.transaction_idRequired, string | Set a unique identifier for each event. Ensure values are unique across all events. |
events.metric_codeRequired, string | Set to the code returned when you created the metric. |
events.external_subscription_idRequired, string | Set to the external_id returned when you created the subscription. |
events.timestampstring | Set the ISO 8601 timestamp when the event occurred. If not provided, PayPal uses the current time. |
events.propertiesRequired for SUM, MAX, COUNT_DISTINCT, and LATEST aggregation types, object | Provide key-value pairs for event properties and usage amounts. The property key (for example, gb or minutes) must match the aggregation_field from your metric configuration. |
201 Created response with the status confirmation.
After you record events and meter usage, PayPal converts this metered data into charges for your customers and bills them. See Understand billing.
2. Optional: Audit usage events
You can retrieve and audit the usage events recorded with PayPal to:- Ensure billing accuracy.
- Resolve customer disputes.
- Validate that all events were saved correctly.
- Ensure that the events recorded match your own tracking systems.