AdGroupService - startIndex too high

14 views
Skip to first unread message

Alex Arias

unread,
Dec 15, 2016, 8:04:13 PM12/15/16
to AdWords API Forum
Hello everyone, 
I recently started seeing an error while trying to use the AdGroupService API to pull the current CPC bids for adgroups in one of my accounts.
This is the code I have been using to do this: 

client.SetClientCustomerId(str(account_id))
ad_group_service = client.GetService('AdGroupService', version='v201605')

PAGE_SIZE = 500

# Get all ad group bid
selector = {
'fields': ['CampaignId', 'CampaignName', 'Id', 'Name', 'CpcBid'],
'predicates': [
{
'field': 'Status',
'operator': 'EQUALS',
'values': 'ENABLED'
}
],
'paging': {
'startIndex': '0',
'numberResults': '500'
}
}

# Set initial values.
offset, page = 0, {}
more_results = True

bids = []
number = 0
while more_results:
page = ad_group_service.get(selector)
if not bids:
print('total number of entries: %s' % int(page['totalNumEntries']))
if page['entries']:
for bid in page['entries']:
current_bid = bid.biddingStrategyConfiguration.bids[0].bid[1]
bid_dict = {'CampaignId': bid['campaignId'],
'AdGroupId': bid['id'],
'CurrentBid': current_bid if current_bid else 0}
number += 1
print('bid number %s' % number)
print(bid_dict)
bids.append(bid_dict)

# Increment values to request the next page.
offset += PAGE_SIZE
selector['paging']['startIndex'] = str(offset)
else:
print('No ad group bid modifiers returned.')
more_results = int(page['totalNumEntries']) > offset
dataframe = pd.DataFrame(bids)
return dataframe

However, the Client Account only contains ~25,000 adgroups but the API is returning a total of ~116,000 adgroups.
I am not sure why the query is returning this large amount of campaign/adgroups. Is there something I am missing?

Thanks, 
Alex


Joyce Lava

unread,
Dec 15, 2016, 9:04:44 PM12/15/16
to AdWords API Forum
Hi Alex,

Could you please send to me (reply privately to author) the complete SOAP request and response and the clientCustomerId used to better check the issue?

Thanks,
Joyce, AdWords API Team
Reply all
Reply to author
Forward
0 new messages