Get Ad Schedule Python API

43 views
Skip to first unread message

Mário Carvalho

unread,
Dec 9, 2024, 3:09:56 AM12/9/24
to Google Ads API and AdWords API Forum
Hello, trying to get Ad Schedule with the following function but result is always empty.

def get_schedule(self, campaign_id):
# Get the GoogleAdsService client
ga_service = self.client.get_service("GoogleAdsService")

# GAQL query to retrieve ad schedules for a specific campaign
query = f"""
SELECT
campaign_criterion.criterion_id,
campaign_criterion.ad_schedule.day_of_week,
campaign_criterion.ad_schedule.start_hour,
campaign_criterion.ad_schedule.start_minute,
campaign_criterion.ad_schedule.end_hour,
campaign_criterion.ad_schedule.end_minute
FROM campaign_criterion
WHERE
campaign.id = {campaign_id} AND
campaign_criterion.type = 'AD_SCHEDULE'
"""

# Execute the search request
try:
response = ga_service.search(customer_id=self.customer_id, query=query)

# Check if the response contains rows
if response.total_results_count == 0:
logger.info(f"No ad schedules found for campaign ID {campaign_id}.")
return []

# Process the rows
schedules = []
for row in response:
ad_schedule = row.campaign_criterion.ad_schedule
schedule_data = {
"criterion_id": row.campaign_criterion.criterion_id,
"day_of_week": ad_schedule.day_of_week.name,
"start_time": f"{ad_schedule.start_hour}:{ad_schedule.start_minute:02d}",
"end_time": f"{ad_schedule.end_hour}:{ad_schedule.end_minute:02d}",
}
schedules.append(schedule_data)
logger.info(f"Ad Schedule: {schedule_data}")

return schedules

except Exception as e:
logger.error(f"Failed to retrieve ad schedules: {e}")
return []

Google Ads API Forum Advisor

unread,
Dec 9, 2024, 6:48:02 AM12/9/24
to mario.c...@wizardsmbile.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads API support team.

As per provided information, I understand that you are trying to retrieve the campaign criterion of type “Ad Schedule” using the Google Ads API but you are not getting the results. I have verified that the provided query is correct and it is returning the desired results. In order to investigate your issue further, please provide the Google Ads customer ID and the campaign ID.

You can send the details via Reply privately to the author option, or direct private reply to this email.

This message is in relation to case "ref:!00D1U01174p.!5004Q02vGnzZ:ref" (ADR-00278090)

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5


 


Mário Carvalho

unread,
Dec 9, 2024, 11:10:04 AM12/9/24
to Google Ads API and AdWords API Forum
Hello, 

when you asked for the customer ID, I understood that I was sending the MCC ID and not the account ID. It was not working this way. With Account ID (where campaign id belongs) workers.

Anyway to get all the adschedules for all the accounts on a MCC?

Thanks

Google Ads API Forum Advisor

unread,
Dec 9, 2024, 2:04:17 PM12/9/24
to mario.c...@wizardsmbile.com, adwor...@googlegroups.com
Hi,

In order to check it our end whether we have this functionality, to get all the adschedules for all the accounts on a MCC, please provide us with the MCC ID and the Google Ads customer ID.
Reply all
Reply to author
Forward
0 new messages