Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Not able to disable the notifications in budget

I want to disable notifications that triggers based on threshold rules defined. I tried it using the Post API but getting 400 error.
API url:  https://billingbudgets.googleapis.com/v1/billingAccounts/{billing_id}/budgets

request body: 

request_body = {
        "displayName": "test-budget",
        "budgetFilter": {
            "projects": [
                "projects/{project_id}"
            ],
            "calendar_period": "QUARTER"
        },
        "amount": {
            "specifiedAmount": {
                "units": 10
            }
        },
        "thresholdRules": {
            "thresholdPercent": 0.8,
            "spendBasis": "CURRENT_SPEND"
        },
        "notificationsRule": {
            "pubsubTopic": "projects/ceq-gcp-finops/topics/test-budget",
            "monitoringNotificationChannels": [
                "testchannel"
            ],
        "disableDefaultIamRecipients": True,
        "enableProjectLevelRecipients": False
        }
    }
1 2 195
2 REPLIES 2

Hi @abhi27 

Here's a step-by-step guide to address your issue:

(1) Correct the API Request URL

Ensure you replace {billing_id} with your actual billing account ID in the API URL:

 

https://billingbudgets.googleapis.com/v1/billingAccounts/{billing_id}/budgets

 

If you're updating an existing budget, you need to append the budget ID to the URL:

 

https://billingbudgets.googleapis.com/v1/billingAccounts/{billing_id}/budgets/{budget_id}

 

(2) Adjust the Request Body to Disable Notifications

 

request_body = {
    "displayName": "test-budget",
    "budgetFilter": {
        "projects": [
            "projects/{project_id}"
        ],
        "calendar_period": "QUARTER"
    },
    "amount": {
        "specifiedAmount": {
            "currency_code": "USD",
            "units": 10
        }
    },
    "thresholdRules": [
        {
            "thresholdPercent": 0.8,
            "spendBasis": "CURRENT_SPEND"
        }
    ]
    # Note: Removed notificationsRule to disable notifications
}

 

(3) Use the correct HTTP Method (POST)

  • Use the correct HTTP method (POST for creating a new budget, PATCH for updating an existing budget).
  • Ensure you have authenticated your request with an appropriate access token.
  • Replace placeholder values ({project_id}, {billing_id}, etc.) with actual values from your GCP environment

Here is a Python code example for making the API Call

 

from google.auth import default
from google.auth.transport.requests import Request
import requests

# Authenticate with Google Cloud
credentials, _ = default()
credentials.refresh(Request())

headers = {
    'Authorization': 'Bearer ' + credentials.token,
    'Content-Type': 'application/json',
}

# Make the API call
response = requests.post(
    'https://billingbudgets.googleapis.com/v1/billingAccounts/{billing_id}/budgets',
    headers=headers,
    json=request_body
)

print(response.json())

 

 I hope that helps

Regards

Mahmoud

 

 

 

 

Hi @mahmoudrabie ,

I already tried using the same request body while creating the budget. Budget has been created successfully, but how do I make sure the notifications are disabled or not?

Apart from this, can you help me the request body in order to enable the notifications using API?

Thanks,

Abhinav