The Data sources sub-API lets you retrieve information about the data sources configured in your Merchant Center account. This can be useful for understanding your current setup, verifying configurations, or integrating with other systems. You can retrieve a specific data source by its ID or list all data sources associated with your account.
For information on how to manage (create, update, delete) data sources for the Products sub-API, see the Manage API data sources for product uploads guide. You can also view your data sources through the Merchant Center user interface. Learn more at Manage your data sources .
Special considerations
There might be a short delay (a few seconds) after creating a data source before
you can retrieve or manipulate it using the get
, list
, delete
or patch
method.
List all data sources
To retrieve a list of all data sources configured for your Merchant Center
account, use the dataSources.list
method.
Keep in mind that the list returned can include data sources that are read-only
through the API, such as those created through the Merchant Center UI (input
type UI
), Autofeeds (input type AUTOFEED
), or Google Sheets (file input type GOOGLE_SHEETS
).
GET https://merchantapi.googleapis.com/datasources/v1/accounts/ {ACCOUNT_ID}
/dataSources
A successful request returns a paginated list of DataSource
resources.
{
"dataSources"
:
[
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000001"
,
"dataSourceId"
:
"100000001"
,
"displayName"
:
"Primary Product API Feed (US)"
,
"primaryProductDataSource"
:
{
"feedLabel"
:
"US"
,
"contentLanguage"
:
"en"
,
"countries"
:
[
"US"
],
"destinations"
:
[
{
"destination"
:
"SHOPPING_ADS"
,
"state"
:
"ENABLED"
},
{
"destination"
:
"FREE_LISTINGS"
,
"state"
:
"ENABLED"
}
]
},
"input"
:
"API"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000002"
,
"dataSourceId"
:
"100000002"
,
"displayName"
:
"Merchant Center UI Product Feed"
,
"primaryProductDataSource"
:
{
"feedLabel"
:
"GB"
,
"contentLanguage"
:
"en"
,
"countries"
:
[
"GB"
]
},
"input"
:
"UI"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000003"
,
"dataSourceId"
:
"100000003"
,
"displayName"
:
"Autofeed Products"
,
"primaryProductDataSource"
:
{
"countries"
:
[
"DE"
]
},
"input"
:
"AUTOFEED"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000004"
,
"dataSourceId"
:
"100000004"
,
"displayName"
:
"API Promotions Feed (FR)"
,
"promotionDataSource"
:
{
"targetCountry"
:
"FR"
,
"contentLanguage"
:
"fr"
},
"input"
:
"API"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000005"
,
"dataSourceId"
:
"100000005"
,
"displayName"
:
"API Local Inventory Feed (US Stores)"
,
"localInventoryDataSource"
:
{
"feedLabel"
:
"US_Stores"
,
"contentLanguage"
:
"en"
},
"input"
:
"API"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000006"
,
"dataSourceId"
:
"100000006"
,
"displayName"
:
"Supplemental Product API Feed (All Targets)"
,
"supplementalProductDataSource"
:
{},
"input"
:
"API"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000007"
,
"dataSourceId"
:
"100000007"
,
"displayName"
:
"Primary Product File Feed (CA)"
,
"primaryProductDataSource"
:
{
"feedLabel"
:
"CA"
,
"contentLanguage"
:
"en"
,
"countries"
:
[
"CA"
]
},
"input"
:
"FILE"
,
"fileInput"
:
{
"fetchSettings"
:
{
"enabled"
:
true
,
"timeOfDay"
:
{
"hours"
:
2
},
"timeZone"
:
"America/Toronto"
,
"frequency"
:
"FREQUENCY_DAILY"
,
"fetchUri"
:
"sftp://example.com/feeds/ca_products.xml"
},
"fileInputType"
:
"FETCH"
}
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000008"
,
"dataSourceId"
:
"100000008"
,
"displayName"
:
"API Product Reviews Feed"
,
"productReviewDataSource"
:
{},
"input"
:
"API"
},
{
"name"
:
"accounts/ {ACCOUNT_ID}
/dataSources/100000009"
,
"dataSourceId"
:
"100000009"
,
"displayName"
:
"API Merchant Reviews Feed"
,
"merchantReviewDataSource"
:
{},
"input"
:
"API"
}
]
}
The following samples demonstrate how to list all data sources for your account. The response will include all types of data sources, including API-managed feeds, file feeds, UI feeds, and Autofeeds.
Java
import
com.google.api.gax.core.FixedCredentialsProvider
;
import
com.google.auth.oauth2.GoogleCredentials
;
import
com.google.shopping.merchant.datasources.v1.DataSource
;
import
com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient
;
import
com.google.shopping.merchant.datasources.v1.DataSourcesServiceClient.ListDataSourcesPagedResponse
;
import
com.google.shopping.merchant.datasources.v1.DataSourcesServiceSettings
;
import
com.google.shopping.merchant.datasources.v1.ListDataSourcesRequest
;
import
java.util.ArrayList
;
import
shopping.merchant.samples.utils.Authenticator
;
import
shopping.merchant.samples.utils.Config
;
/** This class demonstrates how to list all the datasources for a given Merchant Center account */
public
class
ListDataSourcesSample
{
private
static
String
getParent
(
String
accountId
)
{
return
String
.
format
(
"accounts/%s"
,
accountId
);
}
public
static
ArrayList<DataSource>
listDataSources
(
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.
DataSourcesServiceSettings
dataSourcesServiceSettings
=
DataSourcesServiceSettings
.
newBuilder
()
.
setCredentialsProvider
(
FixedCredentialsProvider
.
create
(
credential
))
.
build
();
// Creates parent to identify the account from which to list all the datasources.
String
parent
=
getParent
(
config
.
getAccountId
().
toString
());
// Calls the API and catches and prints any network failures/errors.
try
(
DataSourcesServiceClient
dataSourcesServiceClient
=
DataSourcesServiceClient
.
create
(
dataSourcesServiceSettings
))
{
// The parent has the format: accounts/{account}
ListDataSourcesRequest
request
=
ListDataSourcesRequest
.
newBuilder
().
setParent
(
parent
).
build
();
System
.
out
.
println
(
"Sending list datasources request:"
);
ListDataSourcesPagedResponse
response
=
dataSourcesServiceClient
.
listDataSources
(
request
);
int
count
=
0
;
ArrayList<DataSource>
dataSources
=
new
ArrayList<DataSource>
();
ArrayList<DataSource>
justPrimaryDataSources
=
new
ArrayList<DataSource>
();
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
for
(
DataSource
element
:
response
.
iterateAll
())
{
System
.
out
.
println
(
element
);
count
++
;
dataSources
.
add
(
element
);
// The below lines show how to filter datasources based on type.
// `element.hasSupplementalProductDataSource()` would give you supplemental
// datasources, etc.
if
(
element
.
hasPrimaryProductDataSource
())
{
justPrimaryDataSources
.
add
(
element
);
}
}
System
.
out
.
print
(
"The following count of elements were returned: "
);
System
.
out
.
println
(
count
);
return
dataSources
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
System
.
exit
(
1
);
return
null
;
// Necessary to satisfy the compiler as we're not returning an
// ArrayList<DataSource> on failure.
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Config
config
=
Config
.
load
();
listDataSources
(
config
);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1\DataSource;
use Google\Shopping\Merchant\DataSources\V1\ListDataSourcesRequest;
/**
* Class to demonstrate listing all the datasources for a given Merchant Center
* account.
*/
class ListDataSourcesSample
{
/**
* Lists all DataSources for the given Merchant Center account.
*
* @param int $merchantId The Merchant Center Account ID.
* @return array An array of DataSources.
*/
public function listDataSources(int $merchantId): array
{
// Gets the OAuth credentials to make the request.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates options config containing credentials for the client to use.
$options = ['credentials' => $credentials];
// Creates a client.
$dataSourcesServiceClient = new DataSourcesServiceClient($options);
$parent = sprintf('accounts/%s', $merchantId);
// Creates the request.
$request = (new ListDataSourcesRequest())
->setParent($parent);
print('Sending list datasources request:' . PHP_EOL);
// Calls the API and catches and prints any network failures/errors.
try {
$response = $dataSourcesServiceClient->listDataSources($request);
$dataSources = [];
$justPrimaryDataSources = [];
/** @var DataSource $element */
foreach ($response as $element) {
print($element->serializeToJsonString() . PHP_EOL);
$dataSources[] = $element;
// The below lines show how to filter datasources based on type.
// `element.hasSupplementalProductDataSource()` would give you supplemental
// datasources, etc.
if ($element->hasPrimaryProductDataSource()) {
$justPrimaryDataSources[] = $element;
}
}
print('The following count of datasources were returned: ' . count($dataSources) . PHP_EOL);
print('... of which are primary datasources: ' . count($justPrimaryDataSources) . PHP_EOL);
return $dataSources;
} catch (ApiException $ex) {
print('Call failed with message: ' . $ex->getMessage() . PHP_EOL);
return [];
}
}
// Helper to execute the sample.
public function callSample(): void
{
$config = Config::generateConfig();
// The Merchant Center Account ID.
$merchantId = $config['accountId'];
self::listDataSources($merchantId);
}
}
$sample = new ListDataSourcesSample();
$sample->callSample();