API paging while deleting

28 views
Skip to first unread message

Don Mitchell

unread,
Mar 7, 2019, 9:53:38 AM3/7/19
to AdWords API and Google Ads API Forum
If my account has over 5000 of an object type (say ad_group, feed mapping, feed items, keywords),
If I write a loop intending to remove them all,
If the loop first does a get where status = ENABLED for the 5000 page size,
then the loop does a mutate with operation REMOVE against all the entities retrieved by the get,

ON the next iteration of the loop, should the GET operation start_index be 0 or 5000?

That is, does Google know I'm paging through a result set and is careful to keep the cursor and progress it (e.g., so as to not return duplicates since the results are unordered and there's nothing sacred about result foo being the ith result) or does it do a fresh query and thus the first 5000 which now have status = REMOVED won't be in the result; so the start_index should be 0?

Perhaps the right (always sound) way, would be to do an initial query to get the total_num_entries and then iterate backwards from that number to 0 in chunks of 5000, but that unnecessarily increases my queries by 1 which seems excessive if 99.9% of these accounts have less than 5000 entries.

googleadsapi...@google.com

unread,
Mar 7, 2019, 4:16:06 PM3/7/19
to AdWords API and Google Ads API Forum
Hi Don,

If I understood your implementation correct, you are performing a get on a first set of entities and performing a mutate to remove those items. Since the remove is already performed, your next API call which performs the get operation should not include the removed entities. The totalNumEntries in the response at any point should give you the total count of the entities matching the selector irrespective of the start index and the numberResults in the request. For instance, once you delete the first 5000 entities, the totalNumEntries in the subsequent get operation should be 5000 less than what you had in your first get call. Please let me know if this addressed your question.

Also, please note that the limit on results per page in the response is 10,000. You could check here for the system limits.

Thanks,
Sreelakshmi, AdWords API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

Reply all
Reply to author
Forward
0 new messages