

AWS Marketplace API 参考已重组。有关支持的 API 操作的更多信息，请参阅 [AWS Marketplace API 参考](https://docs.aws.amazon.com/marketplace/latest/APIReference/Welcome.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用目录数据构建接口
<a name="build-interfaces-with-catalog-data"></a>

您可以使用 AWS Marketplace Discovery API 以编程方式访问目录，并在自己的平台上显示产品和定价信息。本节介绍如何使用 Discovery API 构建自定义界面，例如店面、合作伙伴门户和集成销售体验，供客户浏览。

## 架构概述
<a name="discovery-seller-architecture"></a>

典型的集成遵循以下模式：

1. **浏览体验** — 致电`SearchListings`以根据搜索文本和筛选条件检索房源摘要，并在`SearchFacets`类别导航和筛选选项中填充计数。

1. **商品详情页面** — 致电`GetListing`或`GetProduct`展示完整的商品详情、媒体和评论。

1. **定价显示** — 致电`ListPurchaseOptions``GetOffer`、和`GetOfferTerms`以显示定价选项。

## 打造浏览体验
<a name="discovery-seller-browse"></a>

用于`SearchListings`根据搜索文本和筛选条件检索房源摘要，并`SearchFacets`用于构建动态筛选器导航。方面包括类别、配送类型、定价模式、定价单位、发布商和部署状态。每个分面值都包括匹配列表的数量，您可以将其与筛选选项一起显示。

```
import boto3

client = boto3.client('marketplace-discovery', region_name='us-east-1')

# Get facet values for building filter navigation
facets = client.search_facets(
    facetTypes=['CATEGORY', 'FULFILLMENT_OPTION_TYPE', 'PRICING_MODEL']
)

for facet_type, values in facets['listingFacets'].items():
    print(f"\n{facet_type}:")
    for facet in values:
        print(f"  {facet['displayName']} ({facet['count']})")

# Search listings with filters applied from user selections
response = client.search_listings(
    searchText='machine learning',
    filters=[
        {
            'filterType': 'CATEGORY',
            'filterValues': ['Machine Learning']
        },
        {
            'filterType': 'PRICING_MODEL',
            'filterValues': ['USAGE']
        }
    ],
    sortBy='RELEVANCE',
    maxResults=25
)

for listing in response['listingSummaries']:
    print(f"{listing['listingName']} - {listing['shortDescription']}")
```

## 创建商品详情页面
<a name="discovery-seller-product-pages"></a>

`GetProduct`使用`GetListing`或显示完整的商品详情、媒体和评论。`GetListing`当您需要列表概览（包括徽章、类别和定价摘要）时使用。`GetProduct`当您需要详细的产品信息（例如描述、亮点和媒体）时使用。致电`ListFulfillmentOptions`以检索特定产品的部署选项。

```
def get_product_page_data(listing_id, product_id):
    """Retrieve data for a product detail page."""

    # Use GetListing for listing-level overview
    listing = client.get_listing(listingId=listing_id)

    # Or use GetProduct for detailed product information
    product = client.get_product(productId=product_id)

    # Get deployment options for the product
    fulfillment = client.list_fulfillment_options(productId=product_id)

    return {
        'listing': listing,
        'product': product,
        'fulfillmentOptions': fulfillment
    }
```

## 显示定价信息
<a name="discovery-seller-pricing"></a>

使用`ListPurchaseOptions`查找产品的可用报价，`GetOffer`然后`GetOfferTerms`用于检索详细定价。显示定价模型、价目表和期限详细信息，以帮助您的客户评估选项。

```
def get_pricing_for_product(product_id):
    """Retrieve pricing options for display."""
    options = client.list_purchase_options(
        filters=[{
            'filterType': 'PRODUCT_ID',
            'filterValues': [product_id]
        }]
    )

    pricing = []
    for option in options.get('purchaseOptions', []):
        for entity in option['associatedEntities']:
            offer = client.get_offer(
                offerId=entity['offer']['offerId']
            )
            terms = client.get_offer_terms(
                offerId=entity['offer']['offerId']
            )
            pricing.append({
                'option': option,
                'offer': offer,
                'terms': terms
            })

    return pricing
```

## 最佳实践
<a name="discovery-seller-best-practices"></a>
+ **缓存响应**-产品和定价数据不经常更改。将 API 响应缓存 15—60 分钟，以减少 API 调用并缩短页面加载时间。
+ **处理分页**-`nextToken` 用于检索分页操作的所有结果。分页令牌将在 24 小时后过期。
+ **实现重试逻辑**-对 `ThrottlingException` (HTTP 429) 响应使用指数退避。
+ **显示归因** — 在您的平台上显示 AWS Marketplace 数据时，请遵循[AWS 商标指南](https://aws.amazon.com/trademark-guidelines/)。
+ **尽量减少 API 调**用-`SearchListings` 用于摘要数据`GetProduct`，并且仅在用户导航到特定产品时使用通话详情 API (`GetOffer`、、`GetOfferTerms`)。

**注意**  
Discovery API 支持所有产品类型 AWS Marketplace，包括 SaaS、AI 代理和工具、AMI、容器和机器学习模型。您的界面可以显示目录的全部内容。