查看商品统计信息和问题

使用 Merchant API 中的 aggregateProductStatuses.list 方法,大致了解 Merchant Center 账号中商品的状态。通过此方法,您可以监控商品数据的整体健康状况,而无需提取每件商品的数据。它会返回按状态(有效、即将过期、待审批和已拒登)细分的商品总数,并列出影响您商品的商品级问题。

特别注意事项

使用 aggregateProductStatuses.list 时,请注意以下事项:

  • 数据可用性:从您插入或更新商品到 aggregateProductStatuses 响应反映更新后的状态,预计会有超过 30 分钟的延迟。
  • 账号类型:只有独立账号和高级账号的子账号可以调用此方法。如需检索高级账号的汇总商品状态,请先调用 accounts.listSubaccounts 以获取其子账号,然后分别为每个子账号调用 aggregateProductStatuses.list。
  • 即将过期的商品 (expiringCount):expiringCount 字段统计的是即将过期的有效(符合条件)商品,而不是已经过期的商品。符合条件的产品会在其有效失效日期之前 3 天(72 小时)的日历日 00:00:00 UTC 从 activeCount 变为 expiringCount,因此产品通常会在到期前 3 到 4 个日历日(世界协调时间 [UTC])进入 expiringCount。对于给定的报告上下文和国家/地区,activeCount 和 expiringCount 互斥,并且 expiringCount 绝不包含待审核或被拒批的商品。
  • 仅限汇总计数:aggregateProductStatuses.list 方法会返回汇总统计信息,而不会识别单个商品。如需识别即将到期的单个商品,请使用 Reports 子 API 中的 reports.search 查询 product_view 表,并检查 expiration_date(例如,使用 ORDER BY expiration_date ASC 对符合条件的商品进行排序)。如需详细了解如何查询 product_view,请参阅评估您的商品。
  • 问题一致性:aggregateProductStatuses.list 中的问题说明和详细信息与 Products 子 API 中的说明和详细信息一致,但可能与 Merchant Center 界面中显示的说明不同。

一览所有商品状态

此示例展示了如何检索 AggregateProductStatus 资源列表。每个资源都代表特定报告上下文和国家/地区组合的商品状态。在不使用 filter 参数的情况下调用 aggregateProductStatuses.list 会返回您账号的所有可用状态。

GET https://merchantapi.googleapis.com/issueresolution/v1/accounts/{ACCOUNT_ID}/aggregateProductStatuses

以下是成功调用的示例响应:

{
  "aggregateProductStatuses": [
    {
      "name": "accounts/{ACCOUNT_ID}/aggregateProductStatuses/SHOPPING_ADS~US",
      "reportingContext": "SHOPPING_ADS",
      "country": "US",
      "stats": {
        "activeCount": "1500",
        "pendingCount": "50",
        "disapprovedCount": "25",
        "expiringCount": "12"
      },
      "itemLevelIssues": [
        {
          "code": "item_missing_required_attribute",
          "severity": "DISAPPROVED",
          "resolution": "MERCHANT_ACTION",
          "attribute": "n:image_link",
          "description": "Missing product image",
          "detail": "Add an image so customers can easily identify your product",
          "documentationUri": "https://support.google.com/merchants/answer/12158124",
          "productCount": "15"
        },
        {
          "code": "invalid_price",
          "severity": "DISAPPROVED",
          "resolution": "MERCHANT_ACTION",
          "attribute": "n:price",
          "description": "Invalid price format [price]",
          "detail": "Use a valid price format such as \"1.00 EUR\" (ISO 4217)",
          "documentationUri": "https://support.google.com/merchants/answer/6324371",
          "productCount": "10"
        }
      ]
    },
    {
      "name": "accounts/{ACCOUNT_ID}/aggregateProductStatuses/FREE_LISTINGS~US",
      "reportingContext": "FREE_LISTINGS",
      "country": "US",
      "stats": {
        "activeCount": "1510",
        "pendingCount": "50",
        "disapprovedCount": "15",
        "expiringCount": "12"
      },
      "itemLevelIssues": [
        {
          "code": "item_missing_required_attribute",
          "severity": "DISAPPROVED",
          "resolution": "MERCHANT_ACTION",
          "attribute": "n:image_link",
          "description": "Missing product image",
          "detail": "Add an image so customers can easily identify your product",
          "documentationUri": "https://support.google.com/merchants/answer/12158124",
          "productCount": "15"
        }
      ]
    }
  ]
}

获取特定国家/地区和报告上下文的商品状态

通过将 filter 查询参数与 aggregateProductStatuses.list 结合使用,过滤特定国家/地区和报告背景的结果。过滤仅支持 country 和 reportingContext 字段以及 = 和 != 运算符,并与 AND 或带括号的 OR 表达式结合使用。例如:country = "US" AND reportingContext = "SHOPPING_ADS"。如需详细了解常规过滤条件语法,请参阅过滤条件语法。

GET https://merchantapi.googleapis.com/issueresolution/v1/accounts/{ACCOUNT_ID}/aggregateProductStatuses?filter=country%3D%22US%22%20AND%20reportingContext%3D%22SHOPPING_ADS%22

以下是成功调用的示例响应:

{
  "aggregateProductStatuses": [
    {
      "name": "accounts/{ACCOUNT_ID}/aggregateProductStatuses/SHOPPING_ADS~US",
      "reportingContext": "SHOPPING_ADS",
      "country": "US",
      "stats": {
        "activeCount": "1500",
        "pendingCount": "50",
        "disapprovedCount": "25",
        "expiringCount": "12"
      },
      "itemLevelIssues": [
        {
          "code": "item_missing_required_attribute",
          "severity": "DISAPPROVED",
          "resolution": "MERCHANT_ACTION",
          "attribute": "n:image_link",
          "description": "Missing product image",
          "detail": "Add an image so customers can easily identify your product",
          "documentationUri": "https://support.google.com/merchants/answer/12158124",
          "productCount": "15"
        },
        {
          "code": "invalid_price",
          "severity": "DISAPPROVED",
          "resolution": "MERCHANT_ACTION",
          "attribute": "n:price",
          "description": "Invalid price format [price]",
          "detail": "Use a valid price format such as \"1.00 EUR\" (ISO 4217)",
          "documentationUri": "https://support.google.com/merchants/answer/6324371",
          "productCount": "10"
        }
      ]
    }
  ]
}

代码示例

以下代码示例展示了如何使用国家/地区过滤条件列出汇总商品状态:

Java

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.issueresolution.v1.AggregateProductStatus;
import com.google.shopping.merchant.issueresolution.v1.AggregateProductStatusesServiceClient;
import com.google.shopping.merchant.issueresolution.v1.AggregateProductStatusesServiceClient.ListAggregateProductStatusesPagedResponse;
import com.google.shopping.merchant.issueresolution.v1.AggregateProductStatusesServiceSettings;
import com.google.shopping.merchant.issueresolution.v1.ListAggregateProductStatusesRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to list all the accounts the user making the request has access to.
 */
public class ListAggregateProductStatusesSample {
  public static void listAggregateProductStatuses(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.
    AggregateProductStatusesServiceSettings aggregateProductStatusesServiceSettings =
        AggregateProductStatusesServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (AggregateProductStatusesServiceClient aggregateProductStatusesServiceClient =
        AggregateProductStatusesServiceClient.create(aggregateProductStatusesServiceSettings)) {

      // Gets the account ID from the config file.
      String accountId = config.getAccountId().toString();

      // Creates account name to identify account.
      String accountName = AccountName.newBuilder().setAccount(accountId).build().toString();
      ListAggregateProductStatusesRequest request =
          ListAggregateProductStatusesRequest.newBuilder()
              .setParent(accountName)
              .setFilter("country = \"US\"") // Optionally set a filter.
              .build();

      System.out.println("Sending list aggregate product statuses request");
      ListAggregateProductStatusesPagedResponse response =
          aggregateProductStatusesServiceClient.listAggregateProductStatuses(request);

      int count = 0;

      // 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 (AggregateProductStatus aggregateProductStatus : response.iterateAll()) {
        System.out.println("Printing response:");
        System.out.println(aggregateProductStatus);
        count++;
      }
      System.out.print("The following count of aggregate product statuses were returned: ");
      System.out.println(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();
    listAggregateProductStatuses(config);
  }
}

C#

using System;
using static MerchantApi.Authenticator;
using Google.Api.Gax;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Responses;
using Google.Apis.Http;
using Newtonsoft.Json;
using Google.Shopping.Merchant.IssueResolution.V1;

namespace MerchantApi
{
    /// <summary>
    /// This class demonstrates how to list aggregate product statuses.
    /// </summary>
    public class ListAggregateProductStatusesSample
    {
        public static void ListAggregateProductStatuses()
        {
            // Authenticate using either oAuth or service account
            ICredential auth = Authenticator.Authenticate(
                    MerchantConfig.Load(),
                    // Passing the default scope for Merchant API: https://www.googleapis.com/auth/content
                    AggregateProductStatusesServiceClient.DefaultScopes[0]);

            // Creates the service client.
            var client = new AggregateProductStatusesServiceClientBuilder
            {
                Credential = auth
            }.Build();

            // Calls the API and catches and prints any network failures/errors.
            try
            {
                var request = new ListAggregateProductStatusesRequest
                {
                    // The parent resource for the request.
                    ParentAsAccountName = AccountName.FromAccount(MerchantConfig.Load().MerchantId.ToString()),
                    Filter = "country = \"US\"" // Optionally set a filter.
                };

                Console.WriteLine("Sending list aggregate product statuses request");
                PagedEnumerable<ListAggregateProductStatusesResponse, AggregateProductStatus> response =
                    client.ListAggregateProductStatuses(request);

                int count = 0;

                // 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.
                foreach (var aggregateProductStatus in response)
                {
                    Console.WriteLine("Printing response:");
                    Console.WriteLine(aggregateProductStatus);
                    count++;
                }
                Console.Write("The following count of aggregate product statuses were returned: ");
                Console.WriteLine(count);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error has occurred:");
                Console.WriteLine(e);
            }
        }

        public static void Main(string[] args)
        {
            ListAggregateProductStatuses();
        }
    }
}