# List Accessible Accounts

You can list customers accessible to you with the
[`ListAccessibleCustomers`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice)
method in [`CustomerService`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice).
However, it is necessary
to understand which customers are returned in this type of request.

Listing accessible customers is one of the few requests in the Search Ads 360 Reporting API
that does not require you to specify a customer ID in the request,
and will ignore any supplied
[`login-customer-id`](https://developers.google.com/search-ads/reporting/concepts/call-structure#login_customer_id_header).

The resulting list of customers is based on your OAuth credentials. The
request returns a list of all accounts that you are able to act upon
**directly** given your current credentials.
This will not necessarily include all accounts within the account
hierarchy; rather, it will only include accounts
where your authenticated user has been added with admin or other rights
in the account.

![](https://developers.google.com/static/search-ads/reporting/api/images/account-access-example.png)

Imagine you are user `A` who is an admin for `M1` and `C3` in the two
hierarchies
pictured above. If you were to make a call to the Search Ads 360 Reporting API, for example to
[`SearchAds360Service`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#searchads360service),
you could access information for accounts `M1`, `C1`, `C2`,
and `C3`. However, a call to
[`CustomerService.ListAccessibleCustomers`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice) would
return only `M1` and `C3` since those are the only accounts where user `A` has
**direct** access.

Here is a code example illustrating the use of the
[`CustomerService.ListAccessibleCustomers`](https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services#customerservice)
method:

### Java


```java
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sample;

import com.google.ads.searchads360.v0.lib.SearchAds360Client;
import com.google.ads.searchads360.v0.services.CustomerServiceClient;
import com.google.ads.searchads360.v0.services.ListAccessibleCustomersRequest;
import com.google.ads.searchads360.v0.services.ListAccessibleCustomersResponse;

/** List all customers that can be accessed by the authenticated Google account. */
public class ListAccessibleCustomers {

  public static void main(String[] args) {
    try {
      // Creates a SearchAds360Client with local properties file
      final SearchAds360Client searchAds360Client =
          SearchAds360Client.newBuilder().fromPropertiesFile().build();
      // Creates the Customer Service Client.
      CustomerServiceClient client = searchAds360Client.createCustomerServiceClient();
      new ListAccessibleCustomers().runExample(client);
    } catch (Exception exception) {
      System.err.printf("Failed with exception: %s%n", exception);
      exception.printStackTrace();
      System.exit(1);
    }
  }

  private void runExample(CustomerServiceClient customerServiceClient) {
    ListAccessibleCustomersResponse response =
        customerServiceClient.listAccessibleCustomers(
            ListAccessibleCustomersRequest.getDefaultInstance());

    System.out.printf("Total results: %d%n", response.getResourceNamesCount());

    for (String customerResourceName : response.getResourceNamesList()) {
      System.out.printf("Customer resource name: %s%n", customerResourceName);
    }
  }
}
```

<br />

[Download ListAccessibleCustomers.java](https://developers.google.com/search-ads/reporting/sample-code/ListAccessibleCustomers.java)

### Python


```python
#!/usr/bin/env python
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Lists all accessible customers."""

import traceback
from util_searchads360 import SearchAds360Client


def main(client) -> None:
  customer_service = client.get_customer_service()

  # Issues a list accessible customer request.
  accessible_customers = customer_service.list_accessible_customers()
  result_total = len(accessible_customers.resource_names)
  print(f"Total results: {result_total}")

  resource_names = accessible_customers.resource_names
  for resource_name in resource_names:
    print(f'Accessible customer resource name: "{resource_name}"')


if __name__ == "__main__":
  # SearchAds360Client will read the search-ads-360.yaml configuration file in
  # the home directory if none is specified.
  search_ads_360_client = SearchAds360Client.load_from_file()

  try:
    main(search_ads_360_client)
  except Exception:  # pylint: disable=broad-except
    traceback.print_exc()
```

<br />

[Download list_accessible_customers.py](https://developers.google.com/search-ads/reporting/sample-code/list_accessible_customers.py)