How to add a usage rule to a product

With Billing API, you can add Match All, Formula, or Global usage rules to a product with a recurring charge. To add a new usage rule to a product, use the POST command and, in the request body, indicate usage rule details, for example, the type, specification, rate, and associated charge category.

In the example below, a usage rule with the Match All specification, flat rate, and allowance of 1000 kilobytes is added to the subscription product. The product and the recurring price IDs are specified as path parameters in the endpoint.

Note: For details and parameters' definitions, refere to the Usage rule templates or Billing API Reference documentation.

Use this endpoint to add a usage rule to the product:
POST https://example-public-api.gotransverse.com/billing/2/products/{product_id}/
recurring-prices/{recurring_price_id}/usage-rules

Request

{
"usage_rule_type": "pruct",
"name": "New usage rule on product #1",
"valid_from": "2020-03-02",
"allowance_amount": 1000,
"allowance_uom": "KILOBYTE",
"allowance_type": "RECURRING", 
"recurrence_interval": 7,	
"prorated_on_cancel": true,
"prorated_on_order": true,
"roll_over_type": "UNCAPPED",
"rule_type": "TAPERED",
"spec": {
	"usage_rule_specification_type": "match-all"
},
"status": "ACTIVE",
"usage_rate": {
	"rate_type": "flat",
	"rate": 15,
	"uom": "KILOBYTE",
	"charge_category": {
		"id": "3182",
		"charge_category_type": "usage-charge"
	}
}

Response

{
"usage_rule_type": "product",
"id": "9868",
"name": "New usage rule on product #1",
"status": "ACTIVE",
"allowance_amount": 1000,
"allowance_uom": "KILOBYTE",
"rule_order": 2,
"prorated_on_order": true,
"prorated_on_cancel": true,
"roll_over_type": "UNCAPPED",
"allowance_type": "RECURRING",
"recurrence_interval": 7,
"valid_from": "2020-03-02T00:00:00-06:00",
"rule_type": "TAPERED",
"spec": {
	"usage_rule_specification_type": "match-all"
},
"usage_rate": {
	"rate_type": "flat",
	"id": "109506",
	"uom": "KILOBYTE",
	"rate": 15.00000000000000000000,
	"valid_from": "2020-03-02T00:00:00-06:00",
	"charge_category": {
		"charge_category_type": "usage-charge",
		"id": "3182",
		"name": "def charge cat"
	}
}
}

Deleting product usage rules

You can delete usage rules added to the product either with UI 1.0 or API 2.0. Depending on the status of the usage rule and the product, you may or may not be able to delete the associated usage rule. For example, an active usage rule can be deleted from draft products only; and a draft usage rule can be deleted from the available or draft products. The table below details when a usage rule can be deleted.

Product status/
Usage Rule status
Draft Usage RuleActive Usage Rule
Available ProductCan deleteCan NOT delete
Unavailable ProductCan NOT deleteCan NOT delete
Draft ProductCan deleteCan delete

Use this endpoint to delete a usage rule from a product:
DELETE https://example-public-api.gotransverse.com/billing/2/products/{product_id}/
recurring-prices/{recurring_price_id}/usage-rules/{id}