Add supplemental data source to primary data source
Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to add a supplemental data source to a primary data
source.
Java
// Copyright 2024 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.packageshopping.merchant.samples.productsdatasourcesworkflow.v1;importshopping.merchant.samples.datasources.v1.UpdateDataSourceSample;importshopping.merchant.samples.utils.Config;/** * This class demonstrates how to add supplemental DataSources to the primary DataSource's default * rule. */publicclassAddSupplementalDataSourceToPrimaryDataSourceSample{publicstaticvoidaddSupplementalDataSourceToPrimaryDataSource(Configconfig,StringprimaryDataSourceName,StringfirstSupplementalDataSourceName,StringsecondSupplementalDataSourceName)throwsException{// Update the primary DataSource's default rule to include both supplemental feeds.UpdateDataSourceSampleupdateDatasource=newUpdateDataSourceSample();updateDatasource.updateDataSource(config,primaryDataSourceName,firstSupplementalDataSourceName,secondSupplementalDataSourceName);}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();// The names of the primary and supplemental datasources.StringprimaryDataSourceName="accounts/{account_id}/dataSources/{datasource_id}";StringfirstSupplementalDataSourceName="accounts/{account_id}/dataSources/{datasource_id}";StringsecondSupplementalDataSourceName="accounts/{account_id}/dataSources/{datasource_id}";addSupplementalDataSourceToPrimaryDataSource(config,primaryDataSourceName,firstSupplementalDataSourceName,secondSupplementalDataSourceName);}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-13 UTC."],[[["\u003cp\u003eThis Java code sample demonstrates how to add supplemental DataSources to a primary DataSource's default rule within the Google Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eaddSupplementalDataSourceToPrimaryDataSource\u003c/code\u003e method updates the primary DataSource by incorporating specified supplemental feeds.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eUpdateDataSourceSample\u003c/code\u003e class is used to facilitate the update process of a given primary DataSource.\u003c/p\u003e\n"],["\u003cp\u003eThe main method showcases the configuration and invocation of the \u003ccode\u003eaddSupplementalDataSourceToPrimaryDataSource\u003c/code\u003e method with placeholders for account and datasource IDs.\u003c/p\u003e\n"],["\u003cp\u003eThe code is under the Apache License 2.0.\u003c/p\u003e\n"]]],["This Java code sample demonstrates adding supplemental DataSources to a primary DataSource's default rule. It utilizes the `UpdateDataSourceSample` class to update the primary DataSource. The `addSupplementalDataSourceToPrimaryDataSource` method takes configuration, the primary DataSource name, and two supplemental DataSource names as parameters. This method then updates the primary DataSource's rule. The `main` method sets up the configuration and specifies placeholder names for the primary and supplemental DataSources before invoking the primary method.\n"],null,["# Add supplemental data source to primary data source\n\nMerchant API code sample to add a supplemental data source to a primary data\nsource. \n\n### Java\n\n // Copyright 2024 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.merchant.samples.productsdatasourcesworkflow.v1;\n import shopping.merchant.samples.datasources.v1.UpdateDataSourceSample;\n import shopping.merchant.samples.utils.Config;\n\n /**\n * This class demonstrates how to add supplemental DataSources to the primary DataSource's default\n * rule.\n */\n public class AddSupplementalDataSourceToPrimaryDataSourceSample {\n\n public static void addSupplementalDataSourceToPrimaryDataSource(\n Config config,\n String primaryDataSourceName,\n String firstSupplementalDataSourceName,\n String secondSupplementalDataSourceName)\n throws Exception {\n\n // Update the primary DataSource's default rule to include both supplemental feeds.\n UpdateDataSourceSample updateDatasource = new UpdateDataSourceSample();\n updateDatasource.updateDataSource(\n config,\n primaryDataSourceName,\n firstSupplementalDataSourceName,\n secondSupplementalDataSourceName);\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n // The names of the primary and supplemental datasources.\n String primaryDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n String firstSupplementalDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n String secondSupplementalDataSourceName = \"accounts/{account_id}/dataSources/{datasource_id}\";\n\n addSupplementalDataSourceToPrimaryDataSource(\n config,\n primaryDataSourceName,\n firstSupplementalDataSourceName,\n secondSupplementalDataSourceName);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/productsdatasourcesworkflow/v1/AddSupplementalDataSourceToPrimaryDataSourceSample.java"]]