Create Spend Policy
POST/accounts/{account_id}/billing/spend-policies
Creates a spend policy. Each account can have only one enabled usage_block policy per product. A second one returns 409. There is no limit on notification policies.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
Example:
API Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
Example:
The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
Example:
Body ParametersJSON
Create Spend Policy
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/billing/spend-policies \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{
"action": "notification",
"enabled": true,
"name": "Durable Objects alert",
"product_id": "durable_objects",
"threshold_cents": 100,
"notification_email": "billing@example.com"
}'{
"errors": [
{
"message": "message",
"code": 0
}
],
"messages": [
{
"message": "message",
"code": 0
}
],
"result": {
"id": "6f1c2b8e-3d4a-4f5b-9c6d-7e8f9a0b1c2d",
"account_id": 1234567,
"action": "notification",
"enabled": true,
"name": "Workers cap",
"notification_email": "billing@example.com",
"product_id": "workers",
"threshold_cents": 100,
"version": 1,
"current_state": {
"balance_cents": 0,
"billing_period_end": "2019-12-27T18:11:19.117Z",
"billing_period_start": "2019-12-27T18:11:19.117Z",
"enforcement": {
"applied_generation": 0,
"delivery_status": "pending",
"desired_generation": 0,
"desired_state": "active",
"expires_at": "2019-12-27T18:11:19.117Z"
},
"evaluated_at": "2019-12-27T18:11:19.117Z",
"status": "disabled"
}
},
"success": true
}Returns Examples
{
"errors": [
{
"message": "message",
"code": 0
}
],
"messages": [
{
"message": "message",
"code": 0
}
],
"result": {
"id": "6f1c2b8e-3d4a-4f5b-9c6d-7e8f9a0b1c2d",
"account_id": 1234567,
"action": "notification",
"enabled": true,
"name": "Workers cap",
"notification_email": "billing@example.com",
"product_id": "workers",
"threshold_cents": 100,
"version": 1,
"current_state": {
"balance_cents": 0,
"billing_period_end": "2019-12-27T18:11:19.117Z",
"billing_period_start": "2019-12-27T18:11:19.117Z",
"enforcement": {
"applied_generation": 0,
"delivery_status": "pending",
"desired_generation": 0,
"desired_state": "active",
"expires_at": "2019-12-27T18:11:19.117Z"
},
"evaluated_at": "2019-12-27T18:11:19.117Z",
"status": "disabled"
}
},
"success": true
}