Fetch adgroups/campaigns sorted by last updated

50 views
Skip to first unread message

Istiak Mahmod

unread,
Mar 28, 2024, 11:54:39 AM3/28/24
to Google Ads API and AdWords API Forum
Greetings
Is there any way to fetch adgroups/campaigns sorted by last updated time. Currently I am fetching data using these methods. What changes should I make ?
def fetch_adgroups(self, login_id=None, campaign_ids=None):
""" Fetches ad groups from Google.

Note: The AdWords API limits the number of results per request:
To successfully retrieve results, we chunk our requests by campaign ID.

Args:
campaign_ids: optional, filter by campaigns
"""
logging.info('Fetching ad groups from Google.')
if campaign_ids:
logging.info('Filtering on %s campaign IDs.', len(campaign_ids))

query = """
SELECT
ad_group.status
FROM ad_group
WHERE ad_group.status = 'ENABLED'"""

if campaign_ids:
campaign_ids_str = "','".join(map(str, campaign_ids))
query += f" AND campaign.id IN ('{campaign_ids_str}')"

adgroups = []
for row in self.__make_search(query, self.adwords_customer_id, True, login_id):
adgroups.append(zeep_helpers.serialize_object(row))

logging.info('Fetched %s ad groups from Google.', len(adgroups))
return adgroups

def fetch_campaigns(self, login_id=None):
""" Fetches campaigns from Google."""
logging.info('Fetching campaigns from Google.')

query = """
SELECT
campaign.status
FROM campaign
WHERE campaign.status = 'ENABLED'
ORDER BY campaign.id"""
campaigns = []

for row in self.__make_search(query, self.adwords_customer_id, True, login_id):
campaigns.append(zeep_helpers.serialize_object(row))

logging.info('Fetched %s campaigns from Google.', len(campaigns))
return campaigns

Google Ads API Forum Advisor

unread,
Apr 1, 2024, 1:36:48 AM4/1/24
to adwor...@googlegroups.com
Hi,

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

Could you confirm whether the updated time you are looking for the campaign or ad group resource was modified? If yes, then I would recommend checking out the change_event report as it will provide details of the changes made to your resources, as well as the change_event.change_date_time

If this is not what you're looking for, provide more information or relevant screenshots of the UI report you want to retrieve from the API. Also, could you let us know whether you have tried the same functionality via UI?

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.!5004Q02s0Jue:ref" (ADR-00229141)

Thanks,
 
Google Logo Google Ads API Team


Istiak Mahmod

unread,
Apr 5, 2024, 6:02:35 AM4/5/24
to Google Ads API and AdWords API Forum
From here, I can see the changes (and ultimately change date of resource) made within last month. But what if I wanted to see change date which is before 1 month i.e. since I want to fetch campaigns/adgroups which were modified not just within last month and then sort them by change/modified date.
Reply all
Reply to author
Forward
0 new messages