Hi there
I have three questions to get accounts information(name, id, parent id)
Is there any sample code to get all accounts detail(name, id, parent id) information fast? It looks like If I have many accounts like 5,000, I need to make requests 5000 times. So please let me know If I can get all accounts within only one API call or a couple of times and If you leave some sample code for it Like Adwords have some code about it, would be really helpful.
- https://developers.google.com/adwords/api/docs/samples/java/account-management#get-the-account-hierarchy-under-the-current-account
How can I get only enabled accounts? Let say I have 5,000 actual accounts but enabled accounts are about 2,000. So I want just that enabled accounts list (name, id, parent id).
With AdWords API it's really easy to get it like below.
int offset = 0; int PAGE_SIZE = 5000; SelectorBuilder selectorBuilder = new SelectorBuilder() .fields(ManagedCustomerField.CustomerId, ManagedCustomerField.Name, ManagedCustomerField.CanManageClients) .equals(ManagedCustomerField.CanManageClients, String.valueOf(false)).offset(offset).limit(PAGE_SIZE); ManagedCustomerPage page; page = managedCustomerService.get(selectorBuilder.build()); for (ManagedCustomer customer : page.getEntries()) { log.debug("customer: {}", customer.getName()); }
Here is code I tried it to get all accounts.. please let me know a better approach
// Property setting Resource resource = new ClassPathResource("/ads.properties"); Properties props = PropertiesLoaderUtils.loadProperties(resource); props.setProperty("api.googleads.loginCustomerId", "xxxxxxxxx"); // Client create GoogleAdsClient googleAdsClient = GoogleAdsClient.newBuilder().fromProperties(props).build(); GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient(); // Sql setting String customer_client_sql = "SELECT customer.descriptive_name, customer.id, customer_client.resource_name, customer_client.client_customer, customer_client.level, customer_client.hidden FROM customer_client"; // Search One time SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder() .setCustomerId(testManagerId) .setPageSize(10000) .setQuery(customer_client_sql) .build(); // Loop Search to get Detail Customer Information for (GoogleAdsRow row : searchPagedResponse.getPage().getResponse().getResultsList()) { CustomerClient client = row.getCustomerClient(); try { CustomerServiceClient customerService = googleAdsClient.getLatestVersion().createCustomerServiceClient(); Customer cc = customerService.getCustomer(client.getClientCustomer().getValue()); log.debug("customer info: {}", customer); } }
SELECT customer_client.client_customer, customer_client.hidden, customer_client.level, customer_client.manager FROM customer_client
Could you please give this a try with the query above and let me know if you have any issues?
2. I'm afraid, it is currently not possible to filter the customer accounts based on status. There is a feature request already in place for this. Please keep an eye on our blog for more updates.
3. The CUSTOMER_NOT_ENABLED error is usually seen if the account is not completely setup. As mentioned in #2, it is currently not possible to query separately for the enabled accounts.
Let me know if you have any further questions.
Thanks,
Bharani, Google Ads API Team