"The given key was not present in the dictionary"

34 views
Skip to first unread message

Derek Gray

unread,
Nov 5, 2014, 9:31:07 AM11/5/14
to adwor...@googlegroups.com
After I resolved an issue with the "ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISATCH" by adding a predicate to filter "CanManageClients", I started to get an error saying "The given key was not present in the dictionary".

This is what it looks like currently:
Dictionary<long, ManagedCustomerTreeNode> customerIdToCustomerNode = new Dictionary<long, ManagedCustomerTreeNode>();
                       
                       
// Create account tree nodes for each customer.
                       
foreach (ManagedCustomer customer in page.entries) {.....

Any help would be greatly appreciated.


Thanks, 

Josh Radcliff (AdWords API Team)

unread,
Nov 5, 2014, 5:23:44 PM11/5/14
to adwor...@googlegroups.com
Hi,

The error you mentioned is a reporting error, so my guess is that you encountered that because you were using the GetAccountHierarchy.cs example to get all accounts under an MCC and then tried to run a report for each of those accounts, but some of those accounts were MCC accounts. You can avoid the ReportDefinitionError.CUSTOMER_SERVING_TYPE_REPORT_MISMATCH error by only submitting report requests for accounts where ManagedCustomer.canManageClients is false. Accounts where that value is false are standard (non-MCC) AdWords accounts.

Regarding the dictionary error, if that's occurring at line 94 then my guess is that the predicate you added to the ManagedCustomerService.get request was for CanManageClients = false. With that predicate, the ManagedCustomerService.get will only return standard AdWords accounts in the ManagedCustomerPage.entries[]. Therefore the customerIdToCustomerNode dictionary in the example won't have entries for any of the manager (MCC) account IDs, so when the loop at line 92 tries to look up the managed customer for each link in ManagedCustomerPage.links[], it fails. I'd remove that predicate and then use the approach I mentioned in the first paragraph.

Cheers,
Josh, AdWords API Team

Derek Gray

unread,
Nov 6, 2014, 9:04:12 AM11/6/14
to adwor...@googlegroups.com
Your solution worked like a charm! 

Thanks Josh.
Reply all
Reply to author
Forward
0 new messages