Can a row count be obtained without iterating through all rows

39 views
Skip to first unread message

Phil

unread,
Feb 8, 2019, 6:04:24 AM2/8/19
to AdWords API and Google Ads API Forum
Is there a way using GoogleAdsService.search, to obtain a row count of the specified search query without iterating and counting every row?  It doesn't appear that there's a mechanism for this in the query language itself (such as a COUNT aggregate function).  I'm wondering if we can do something similar to what was possible with the AdWords client library, which allowed for a paged response which included the total number of rows in the response.  This allows for the easy obtainment of counts.  Thanks.

googleadsapi...@google.com

unread,
Feb 8, 2019, 3:59:35 PM2/8/19
to AdWords API and Google Ads API Forum
Hello Phil,

To get the count of the rows without iterating you could use the below code code snippet for Java. You could use the similar functionality in other client libraries as well to get the count of the results. Also, the PAGE_SIZE attribute can be mentioned for the search query to get not more than that many results in the response. You could refer our sample code to get campaigns in Java here for reference, code samples in other languages can be found here.

Code snippet in Java:
 searchPagedResponse.getPage().getPageElementCount();

Please let me know if you have any further questions.

Regards,
Sai Teja, Google Ads 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/

Phil

unread,
Feb 8, 2019, 4:07:18 PM2/8/19
to AdWords API and Google Ads API Forum
Thanks for the reply, does this give the row count of the total number of rows that would be returned by the query or just the rows on the page?  The problem I'm trying to solve is obtaining a total count of all rows that would be returned by a given query, without the need to pull all the data over the network.  Let me know what you think, thanks again.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages