Merchant API 서비스를 사용하면 Apps Script에서 Merchant API를 사용하여 제품을 업로드하고 판매자 센터 계정을 관리할 수 있습니다.
Merchant API에 관한 자세한 내용은 참고 문서를 확인하세요. Apps Script의 모든 고급 서비스와 마찬가지로 Merchant API 서비스는 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다.
Merchant API는 하위 API(관련 서비스 및 리소스 그룹) 모음입니다. 다음은 하위 API 목록입니다.
Apps Script에서 Merchant API 서비스를 사용하려면 다음 단계를 따르세요.
- Apps Script 프로젝트가 표준 Google Cloud 프로젝트에 연결되어 있는지 확인합니다. 자세한 내용은 다른 표준 Cloud 프로젝트 사용을 참고하세요. 
- 이 문서에 설명된 대로 Apps Script 고급 서비스를 사용 설정합니다. - 새 프로젝트에 appsscript.json를 사용 설정합니다.
- 기존 프로젝트에 Apps Script를 사용 설정합니다.
 
- 새 프로젝트에 
- 판매자 API 빠른 시작 가이드에 설명된 대로 일반 Google Cloud 프로젝트를 판매자 센터 계정에 등록합니다. 
Apps Script 고급 서비스 사용 설정
다음 두 가지 방법 중 하나를 사용하여 Apps Script 서비스를 사용 설정할 수 있습니다.
appsscript.json에서 API 사용 설정
다음 예는 제품, 계정, 보고서, 데이터 소스 하위 API를 사용 설정하는 appsscript.json 파일을 보여줍니다.
- Apps Script 편집기에서 프로젝트 설정 을 선택합니다.  
- 편집기에 'appsscript.json' 매니페스트 파일 표시 옵션을 사용 설정합니다. 
- 편집기에서 - appsscript.json파일을 선택합니다.
- appsscript.json파일의 콘텐츠를 다음으로 바꿉니다.- { "dependencies": { "enabledAdvancedServices": [ { "userSymbol": "MerchantApiAccounts", "version": "accounts_v1", "serviceId": "merchantapi" }, { "userSymbol": "MerchantApiDataSources", "version": "datasources_v1", "serviceId": "merchantapi" }, { "userSymbol": "MerchantApiProducts", "version": "products_v1", "serviceId": "merchantapi" }, { "userSymbol": "MerchantApiReports", "version": "reports_v1", "serviceId": "merchantapi" } ] }, "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8" }
- 저장을 클릭합니다. 
- 이제 코드 내에서 다음 하위 API를 다음과 같이 참조할 수 있습니다. - a. - MerchantApiAccounts- b. - MerchantApiDataSources- c. - MerchantApiProducts- d. - MerchantApiReports
추가 하위 API 또는 기존 프로젝트에 Apps Script 사용 설정
기존 프로젝트에서 하위 API를 사용 설정하려면 다음 단계를 따르세요.
- Apps Script 프로젝트를 엽니다. 
- 왼쪽에서 편집기 < >를 클릭합니다. 
- 왼쪽의 서비스 옆에 있는 서비스 추가 +를 클릭합니다. 
- 버전 선택기에서 사용 설정할 하위 API를 선택합니다. 
- 하위 API의 이름이 포함된 식별자를 추가합니다. 예를 들어 인벤토리 하위 API를 사용 설정하려면 버전 - inventories_v1을 선택하고 식별자를- MerchantApiInventories로 변경합니다. 
- 이제 코드 내에서 인벤토리 하위 API를 - MerchantApiInventories로 참조할 수 있습니다.
샘플 코드
이 섹션에서는 선택한 기능에 Merchant API를 사용하는 방법을 설명합니다.
제품 나열
이 예에서는 특정 판매자 센터 계정의 제품을 나열하는 방법을 보여줍니다.
/**
 * Lists all products for a given Merchant Center account.
 */
function productList() {
  // IMPORTANT:
  // Enable the Merchant API Products sub-API Advanced Service and call it
  // "MerchantApiProducts"
  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';
  // Construct the parent name
  const parent = 'accounts/' + accountId;
  try {
    console.log('Sending list Products request');
    let pageToken;
    // Set the page size to 1000. This is the maximum allowed page size.
    let pageSize = 1000;
    console.log('Retrieved products below:');
    // Call the Products.list API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response = MerchantApiProducts.Accounts.Products.list(parent, {pageToken, pageSize});
      console.log(response);
      pageToken = response.nextPageToken;
    } while (pageToken); // Exits when there is no next page token.
  } catch (e) {
    console.log('ERROR!');
    console.log(e);
  }
}
비승인 제품 필터링
이 예에서는 판매자 센터 계정에서 비승인 제품을 필터링하는 방법을 보여줍니다.
/**
 * Demonstrates how to filter disapproved products using the Merchant API Reports service.
 */
function filterDisapprovedProducts() {
  // IMPORTANT:
  // Enable the Merchant API Reports sub-API Advanced Service and call it
  // "MerchantApiReports"
  // Enable the Merchant API Products sub-API Advanced Service and call it
  // "MerchantApiProducts"
  // Replace this with your Merchant Center ID.
  const accountId = '<INSERT_MERCHANT_CENTER_ID>';
  // Construct the parent name
  const parent = 'accounts/' + accountId;
  try {
    console.log('Sending search Report request');
    // Set pageSize to the maximum value (default: 1000)
    let pageSize = 1000;
    let pageToken;
    // The query below is an example of a query for the productView that gets product informations
    // for all disapproved products.
    let query = 'SELECT offer_id,' +
        'id,' +
        'price,' +
        'title' +
        ' FROM product_view' +
        ' WHERE aggregated_reporting_context_status = "NOT_ELIGIBLE_OR_DISAPPROVED"';
    // Call the Reports.search API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiReports.Accounts.Reports.search({query, pageSize, pageToken}, parent);
      for (const reportRow of response.results) {
        console.log("Printing data from Product View:");
        console.log(reportRow);
        // OPTIONALLY, you can get the full product details by calling the GetProduct method.
        let productName = parent + "/products/" + reportRow.getProductView().getId();
        product = MerchantApiProducts.Accounts.Products.get(productName);
        console.log(product);
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.
  } catch (e) {
    console.log('ERROR!');
    console.log('Error message:' + e.message);
  }
}
특정 계정의 보고서 가져오기
이 예에서는 지정된 판매자 센터 계정의 보고서를 가져오는 방법을 보여줍니다.
/**
 * Searches a report for a given Merchant Center account.
 */
function searchReport() {
  // IMPORTANT:
  // Enable the Merchant API Reports sub-API Advanced Service and call it
  // "MerchantApiReports"
  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';
  // Construct the parent name
  const parent = 'accounts/' + accountId;
  try {
    console.log('Sending search Report request');
    // Set pageSize to the maximum value (default: 1000)
    let pageSize = 1000;
    let pageToken;
    // Uncomment the desired query from below. Documentation can be found at
    // https://developers.google.com/merchant/api/reference/rest/reports_v1beta/accounts.reports#ReportRow
    // The query below is an example of a query for the product_view.
    let query = 'SELECT offer_id,' +
        'id,' +
        'price,' +
        'gtin,' +
        'item_issues,' +
        'channel,' +
        'language_code,' +
        'feed_label,' +
        'title,' +
        'brand,' +
        'category_l1,' +
        'product_type_l1,' +
        'availability,' +
        'shipping_label,' +
        'thumbnail_link,' +
        'click_potential' +
        ' FROM product_view';
    /*
    // The query below is an example of a query for the
    price_competitiveness_product_view. let query = "SELECT offer_id,"
                 + "id,"
                 + "benchmark_price,"
                 + "report_country_code,"
                 + "price,"
                 + "title,"
                 + "brand,"
                 + "category_l1,"
                 + "product_type_l1"
                + " FROM price_competitiveness_product_view"
                + " WHERE date BETWEEN '2023-03-03' AND '2025-03-10'"; */
    /*
    // The query below is an example of a query for the
    price_insights_product_view. let query = "SELECT offer_id,"
                     + "id,"
                     + "suggested_price,"
                     + "price,"
                     + "effectiveness,"
                     + "title,"
                     + "brand,"
                     + "category_l1,"
                     + "product_type_l1,"
                     + "predicted_impressions_change_fraction,"
                     + "predicted_clicks_change_fraction,"
                     + "predicted_conversions_change_fraction"
                    + " FROM price_insights_product_view"; */
    /*
    // The query below is an example of a query for the
    product_performance_view. let query = "SELECT offer_id,"
            + "conversion_value,"
            + "marketing_method,"
            + "customer_country_code,"
            + "title,"
            + "brand,"
            + "category_l1,"
            + "product_type_l1,"
            + "custom_label0,"
            + "clicks,"
            + "impressions,"
            + "click_through_rate,"
            + "conversions,"
            + "conversion_rate"
            + " FROM product_performance_view"
            + " WHERE date BETWEEN '2023-03-03' AND '2025-03-10'"; */
    // Call the Reports.search API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiReports.Accounts.Reports.search({query, pageSize, pageToken}, parent);
      for (const reportRow of response.results) {
        console.log(reportRow);
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.
  } catch (e) {
    console.log('ERROR!');
    console.log(e);
    console.log('Error message:' + e.message);
    if (e.stack) {
      console.log('Stack trace:' + e.stack);
    }
  }
}
모든 데이터 소스 나열
이 예에서는 특정 판매자 센터 계정의 모든 데이터 소스를 나열하는 방법을 보여줍니다.
/**
 * Lists all data sources for a given Merchant Center account.
 */
function listDataSources() {
  // IMPORTANT:
  // Enable the Merchant API DataSources sub-API 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);
  }
}