Merchant API code sample to list omnichannel settings.

### Java

    // Copyright 2025 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 shopping.merchant.samples.accounts.omnichannelsettings.v1;

    import com.google.api.gax.core.FixedCredentialsProvider;
    import com.google.auth.oauth2.GoogleCredentials;
    import com.google.shopping.merchant.accounts.v1.AccountName;
    import com.google.shopping.merchant.accounts.v1.ListOmnichannelSettingsRequest;
    import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
    import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
    import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient.ListOmnichannelSettingsPagedResponse;
    import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
    import shopping.merchant.samples.utils.Authenticator;
    import shopping.merchant.samples.utils.Config;

    /**
     * This class demonstrates how to get the list of omnichannel settings for a given Merchant Center
     * account
     */
    public class ListOmnichannelSettingsSample {

      public static void omnichannelSettings(Config config) throws Exception {

        // Obtains OAuth token based on the user's configuration.
        GoogleCredentials credential = new Authenticator().authenticate();

        // Creates service settings using the credentials retrieved above.
        OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
            OmnichannelSettingsServiceSettings.newBuilder()
                .setCredentialsProvider(FixedCredentialsProvider.create(credential))
                .build();

        String accountId = config.getAccountId().toString();
        String parent = AccountName.newBuilder().setAccount(accountId).build().toString();

        // Calls the API and catches and prints any network failures/errors.
        try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
            OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
          ListOmnichannelSettingsRequest request =
              ListOmnichannelSettingsRequest.newBuilder().setParent(parent).build();

          System.out.println("Sending list omnichannel setting request:");
          ListOmnichannelSettingsPagedResponse response =
              omnichannelSettingsServiceClient.listOmnichannelSettings(request);

          int count = 0;

          // Iterates over all the entries in the response.
          for (OmnichannelSetting omnichannelSetting : response.iterateAll()) {
            System.out.println(omnichannelSetting);
            count++;
          }
          System.out.println(String.format("The following count of elements were returned: %d", count));
        } catch (Exception e) {
          System.out.println("An error has occured: ");
          System.out.println(e);
        }
      }

      public static void main(String[] args) throws Exception {
        Config config = Config.load();

        omnichannelSettings(config);
      }
    }

### PHP

    <?php
    /**
     * Copyright 2025 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.
     */
    require_once __DIR__ . '/../../../../vendor/autoload.php';
    require_once __DIR__ . '/../../../Authentication/Authentication.php';
    require_once __DIR__ . '/../../../Authentication/Config.php';
    use Google\ApiCore\ApiException;
    use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
    use Google\Shopping\Merchant\Accounts\V1\ListOmnichannelSettingsRequest;

    /**
     * This class demonstrates how to get the list of omnichannel settings for a
     * given Merchant Center account.
     */
    class ListOmnichannelSettings
    {
        /**
         * Helper to create the parent string.
         *
         * @param string $accountId The merchant account ID.
         * @return string The parent string in the format `accounts/{account}`.
         */
        private static function getParent(string $accountId): string
        {
            return sprintf('accounts/%s', $accountId);
        }

        /**
         * Lists the omnichannel settings for a given Merchant Center account.
         *
         * @param array $config The configuration file for authentication.
         */
        public static function listOmnichannelSettingsSample(array $config): void
        {
            // Obtains OAuth credentials from the configuration file.
            $credentials = Authentication::useServiceAccountOrTokenFile();

            // Creates a client.
            $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
                'credentials' => $credentials
            ]);

            // Constructs the parent resource name.
            $parent = self::getParent($config['accountId']);

            // Creates the request.
            $request = new ListOmnichannelSettingsRequest(['parent' => $parent]);

            // Calls the API and prints the response.
            try {
                printf("Sending list omnichannel setting request:%s", PHP_EOL);
                $response = $omnichannelSettingsServiceClient->listOmnichannelSettings($request);

                $count = 0;
                // Iterates over all the omnichannel settings and prints them.
                foreach ($response->iterateAllElements() as $omnichannelSetting) {
                    print $omnichannelSetting->serializeToJsonString(true) . PHP_EOL;
                    $count++;
                }
                printf("The following count of elements were returned: %d%s", $count, PHP_EOL);
            } catch (ApiException $e) {
                printf("An error has occured: %s", $e->getMessage());
            }
        }

        /**
         * Executes the sample.
         */
        public function callSample(): void
        {
            $config = Config::generateConfig();
            self::listOmnichannelSettingsSample($config);
        }
    }

    // Runs the script.
    $sample = new ListOmnichannelSettings();
    $sample->callSample();

### Python

    # -*- coding: utf-8 -*-
    # Copyright 2025 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
    #
    #     http://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.
    """This class demonstrates how to list omnichannel settings."""

    from examples.authentication import configuration
    from examples.authentication import generate_user_credentials
    from google.shopping.merchant_accounts_v1 import ListOmnichannelSettingsRequest
    from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient


    def list_omnichannel_settings(account_id: str) -> None:
      """Lists the omnichannel settings for a given Merchant Center account.

      Args:
          account_id: The ID of the Merchant Center account.
      """
      # Gets OAuth Credentials.
      credentials = generate_user_credentials.main()

      # Creates a client.
      client = OmnichannelSettingsServiceClient(credentials=credentials)

      # The parent account for which to list the settings.
      parent = f"accounts/{account_id}"

      # Creates the request.
      request = ListOmnichannelSettingsRequest(parent=parent)

      # Makes the request and catches and prints any error messages.
      try:
        print("Sending list omnichannel setting request:")
        response = client.list_omnichannel_settings(request=request)

        count = 0
        # Iterates over all the entries in the response.
        for omnichannel_setting in response:
          print(omnichannel_setting)
          count += 1
        print(f"The following count of elements were returned: {count}")
      except RuntimeError as e:
        print("An error has occured: ")
        print(e)


    if __name__ == "__main__":
      # The ID of the account to get the omnichannel settings for.
      _ACCOUNT = configuration.Configuration().read_merchant_info()

      list_omnichannel_settings(_ACCOUNT)