अपने डेटा सोर्स के कॉन्फ़िगरेशन देखना

डेटा सोर्स सब-एपीआई की मदद से, अपने Merchant Center खाते में कॉन्फ़िगर किए गए डेटा सोर्स के बारे में जानकारी हासिल की जा सकती है. यह आपके मौजूदा सेटअप को समझने, कॉन्फ़िगरेशन की पुष्टि करने या दूसरे सिस्टम के साथ इंटिग्रेट करने के लिए मददगार हो सकता है. किसी डेटा सोर्स को उसके आईडी से वापस पाया जा सकता है या अपने खाते से जुड़े सभी डेटा सोर्स की सूची देखी जा सकती है.

प्रॉडक्ट सब-एपीआई के लिए डेटा सोर्स मैनेज करने (बनाने, अपडेट करने, मिटाने) का तरीका जानने के लिए, प्रॉडक्ट अपलोड करने के लिए एपीआई डेटा सोर्स मैनेज करना गाइड देखें. Merchant Center के यूज़र इंटरफ़ेस से भी अपने डेटा सोर्स देखे जा सकते हैं. ज़्यादा जानने के लिए, अपने डेटा सोर्स मैनेज करें पर जाएं.

ध्यान देने वाली खास बातें

डेटा सोर्स बनाने के बाद, get, list, delete या patch तरीके का इस्तेमाल करके, उसे वापस पाने या उसमें बदलाव करने में कुछ सेकंड लग सकते हैं.

सभी डेटा सोर्स की सूची

अपने Merchant Center खाते के लिए कॉन्फ़िगर किए गए सभी डेटा सोर्स की सूची देखने के लिए, dataSources.list तरीका अपनाएं.

ध्यान रखें कि लिस्ट में ऐसे डेटा सोर्स शामिल हो सकते हैं जो एपीआई के ज़रिए सिर्फ़ पढ़े जा सकते हैं. जैसे, Merchant Center के यूज़र इंटरफ़ेस (इनपुट टाइप UI), ऑटोफ़ीड (इनपुट टाइप AUTOFEED) या Google Sheets (फ़ाइल इनपुट टाइप GOOGLE_SHEETS) से बनाए गए डेटा सोर्स.

GET https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources

अनुरोध पूरा होने पर, DataSource संसाधनों की पेज की गई सूची दिखती है.

{
  "dataSources": [
    {
      "name": "accounts/{ACCOUNT_ID}/dataSources/100000001",
      "dataSourceId": "100000001",
      "displayName": "Primary Product API Feed (US)",
      "primaryProductDataSource": {
        "channel": "ONLINE_PRODUCTS",
        "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": {
        "channel": "ONLINE_PRODUCTS",
        "feedLabel": "GB",
        "contentLanguage": "en",
        "countries": ["GB"]
      },
      "input": "UI"
    },
    {
      "name": "accounts/{ACCOUNT_ID}/dataSources/100000003",
      "dataSourceId": "100000003",
      "displayName": "Autofeed Products",
      "primaryProductDataSource": {
        "channel": "ONLINE_PRODUCTS",
        "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": {
        "channel": "ONLINE_PRODUCTS",
        "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"
    }
  ]
}

यहां दिए गए सैंपल में, आपके खाते के सभी डेटा सोर्स की सूची बनाने का तरीका बताया गया है. जवाब में सभी तरह के डेटा सोर्स शामिल होंगे. इनमें एपीआई से मैनेज किए जाने वाले फ़ीड, फ़ाइल फ़ीड, यूज़र इंटरफ़ेस (यूआई) फ़ीड, और ऑटोफ़ीड शामिल हैं.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient.ListDataSourcesPagedResponse;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.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\V1beta\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1beta\DataSource;
use Google\Shopping\Merchant\DataSources\V1beta\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();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_datasources_v1beta

_ACCOUNT = configuration.Configuration().read_merchant_info()
_PARENT = f"accounts/{_ACCOUNT}"


def list_data_sources():
  """Lists the `DataSource` resources for a given account."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = merchant_datasources_v1beta.DataSourcesServiceClient(
      credentials=credentials
  )

  # Creates the request.
  request = merchant_datasources_v1beta.ListDataSourcesRequest(parent=_PARENT)

  # Makes the request and catch and print any error messages.
  try:
    response = client.list_data_sources(request=request)
    primary_data_sources = []
    for data_source in response.data_sources:
      # PrimaryProductDataSource is a oneOf field. If it is set, then this is a
      # primary data source.
      if data_source.primary_product_data_source:
        primary_data_sources.append(data_source)
    print(
        f"List request successful. You have {len(response.data_sources)} total"
        f" data sources, of which {len(primary_data_sources)} are primary data"
        " sources"
    )
  except RuntimeError as e:
    print("List request failed")
    print(e)


if __name__ == "__main__":
  list_data_sources()

AppsScript


/**
 * Lists all data sources for a given Merchant Center account.
 */
function listDataSources() {
  // IMPORTANT:
  // Enable the Merchant API DataSources Bundle Advanced Service and call it
  // "MerchantApiDataSources"

  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';

  // Construct the parent name
  const parent = 'accounts/' + accountId;
  let dataSources = [];
  let primaryDataSources = [];
  try {
    console.log('Sending list DataSources request');
    let pageToken;
    let pageSize = 10;
    // Call the DataSources.list API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiDataSources.Accounts.DataSources.list(parent, {pageSize, pageToken});
      for (const datasource of response.dataSources) {
        dataSources.push(datasource);
        if (datasource.primaryProductDataSource) {
          primaryDataSources.push(datasource);
        }
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.
    console.log('Retrieved ' + dataSources.length + ' data sources.');
    console.log(
        'There were ' + primaryDataSources.length +
        ' primary product data sources.');
  } catch (e) {
    console.log('ERROR!');
    console.log(e);
  }
}

cURL

curl \
"https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json"

किसी खास डेटा सोर्स के बारे में जानकारी पाना

किसी खास डेटा सोर्स के बारे में जानकारी पाने के लिए, dataSources.get का इस्तेमाल करें. आपको उस डेटा सोर्स का accountId और dataSourceId देना होगा जिसे आपको वापस पाना है.

याद रखें कि डेटा सोर्स बनाने के बाद, इस तरीके का इस्तेमाल करके उसे वापस पाने में थोड़ा समय लग सकता है.

GET https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}

अनुरोध पूरा होने पर, DataSource संसाधन दिखता है.

{
  "name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
  "dataSourceId": "{DATASOURCE_ID}",
  "displayName": "My API Primary Product Source (US-en)",
  "primaryProductDataSource": {
    "channel": "ONLINE_PRODUCTS",
    "feedLabel": "US",
    "contentLanguage": "en",
    "countries": [
      "US"
    ]
  },
  "input": "API"
}

यहां दिए गए सैंपल में, किसी खास डेटा सोर्स को उसके आईडी से वापस पाने का तरीका बताया गया है.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.datasources.v1beta.DataSource;
import com.google.shopping.merchant.datasources.v1beta.DataSourceName;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceClient;
import com.google.shopping.merchant.datasources.v1beta.DataSourcesServiceSettings;
import com.google.shopping.merchant.datasources.v1beta.GetDataSourceRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to get a specific datasource for a given Merchant Center account. */
public class GetDataSourceSample {

  public static DataSource getDataSource(Config config, String dataSourceId) 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 datasource name to identify datasource.
    String name =
        DataSourceName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setDatasource(dataSourceId)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (DataSourcesServiceClient dataSourcesServiceClient =
        DataSourcesServiceClient.create(dataSourcesServiceSettings)) {

      // The name has the format: accounts/{account}/datasources/{datasource}
      GetDataSourceRequest request = GetDataSourceRequest.newBuilder().setName(name).build();

      System.out.println("Sending GET DataSource request:");
      DataSource response = dataSourcesServiceClient.getDataSource(request);

      System.out.println("Retrieved DataSource below");
      System.out.println(response);
      return response;
    } catch (Exception e) {
      System.out.println(e);
      System.exit(1);
      return null; // Necessary to satisfy the compiler as we're not returning a
      // DataSource on failure.
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // An ID assigned to a datasource by Google.
    String datasourceId = "1111111111"; // Replace with your datasource ID.

    getDataSource(config, datasourceId);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\DataSources\V1beta\Client\DataSourcesServiceClient;
use Google\Shopping\Merchant\DataSources\V1beta\DataSource;
use Google\Shopping\Merchant\DataSources\V1beta\GetDataSourceRequest;

/**
 * Class to demonstrate getting a specific datasource for a given Merchant
 * Center account.
 */
class GetDataSourceSample
{
    // ENSURE you fill in the datasource ID for the sample to work.
    private const DATASOURCE_ID = 'INSERT_DATASOURCE_ID';

    /**
     * Gets a DataSource.
     *
     * @param int $merchantId The Merchant Center Account ID.
     * @param string $dataSourceId The data source ID.
     * @return DataSource The retrieved data source.
     */
    public function getDataSource(int $merchantId, string $dataSourceId): DataSource
    {
        // 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);

        // Creates the data source name.
        $name = sprintf('accounts/%s/dataSources/%s', $merchantId, $dataSourceId);

        // Creates the request.
        $request = (new GetDataSourceRequest())
            ->setName($name);

        print('Sending GET DataSource request:' . PHP_EOL);

        // Calls the API and catches and prints any network failures/errors.
        try {
            $response = $dataSourcesServiceClient->getDataSource($request);
            print('Retrieved DataSource below' . PHP_EOL);
            print($response->serializeToJsonString() . PHP_EOL);
            return $response;
        } catch (ApiException $ex) {
            print('Call failed with message: ' . $ex->getMessage() . PHP_EOL);
            return new DataSource();
        }
    }

    // Helper to execute the sample.
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The Merchant Center Account ID.
        $merchantId = $config['accountId'];

        self::getDataSource($merchantId, self::DATASOURCE_ID);
    }
}

$sample = new GetDataSourceSample();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping import merchant_datasources_v1beta

# ENSURE you fill in the datasource ID for the sample to
# work.
_ACCOUNT = configuration.Configuration().read_merchant_info()
_DATASOURCE = "[INSERT_DATASOURCE_HERE]"
_NAME = f"accounts/{_ACCOUNT}/dataSources/{_DATASOURCE}"


def get_data_source():
  """Gets the specified `DataSource` resource."""

  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = merchant_datasources_v1beta.DataSourcesServiceClient(
      credentials=credentials
  )

  # Creates the request.
  request = merchant_datasources_v1beta.GetDataSourceRequest(name=_NAME)

  # Makes the request and catch and print any error messages.
  try:
    response = client.get_data_source(request=request)
    print(f"Get successful: {response}")
  except RuntimeError as e:
    print("Get failed")
    print(e)


if __name__ == "__main__":
  get_data_source()

cURL

curl \
"https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json"