Can anyone out there can give me a good reference cuz, i cant find proper 
resources for the same.

1. I tried to retrieve the campaign id first to test things out.
from google.ads.googleads.client import GoogleAdsClient

from dotenv import dotenv_values


def get_campaign_id(campaign_name):
config = dotenv_values(".env")

credentials = {
"developer_token": config["developer_token"],
"refresh_token": config["refresh_token"],
"client_id": config["client_id"],
"client_secret": config["client_secret"],
"use_proto_plus": True
}

googleads_client = GoogleAdsClient.load_from_dict(credentials)

customer_id = config.get("account_id")
print(customer_id)

if not customer_id:
print("Google Ads customer ID not provided.")
return None
ga_service = googleads_client.get_service("GoogleAdsService")

query = f"""
SELECT
campaign.id
FROM
campaign
WHERE
campaign.name = '{campaign_name}'
"""

response = ga_service.search(customer_id=customer_id, query=query)

for row in response:
campaign_id = row.campaign.id
print(f"Campaign ID for '{campaign_name}': {campaign_id}")
return campaign_id

# Example usage
campaign_name_to_find = 'wowdare_united-kingdom_eng'
get_campaign_id(campaign_name_to_find)


I got the output in the console, so it worked well.


2. When i tried to update the budget using another function then it shows 
the error where i was trying to get the existing budget using  
CampaignBudgetOperation. 

Is there any other way to update the existing budget for a specific 
campaign.

*AttributeError: Unknown field for CampaignBudgetOperation: get*

def campaign_budget_update(campaign_id, budget):
config = dotenv_values(".env")

credentials = {
"developer_token": config["developer_token"],
"refresh_token": config["refresh_token"],
"client_id": config["client_id"],
"client_secret": config["client_secret"],
"use_proto_plus": True
}

googleads_client = GoogleAdsClient.load_from_dict(credentials)

customer_id = config.get("account_id")

if not customer_id:
print("Google Ads customer ID not provided.")
return None

campaign_budget_service = googleads_client.get_type(
"CampaignBudgetOperation")

# Construct the campaign budget resource name
campaign_budget_resource_name = campaign_id
#print(campaign_budget_resource_name)

# Get the existing campaign budget to modify
existing_campaign_budget = 
campaign_budget_service.get(campaign_budget_resource_name)

# Update the budget amount
existing_campaign_budget.amount_micros = budget * 1_000_000 # Convert 
budget to micros

# Create a mutate operation to update the campaign budget
operation = googleads_client.types.CampaignBudgetOperation(update
=existing_campaign_budget)

# Execute the mutate operation
response = googleads_client.service.campaign_budget.mutate_campaign_budgets(
customer_id=customer_id,
operations=[operation])

# Print the response
print(f"Budget updated for Campaign ID {campaign_id}. Response: {response}")

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/0a69d7c6-51b1-4c9a-aa5f-2e9023d97bc1n%40googlegroups.com.
  • Tr... Mrinal Pant
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to