

已重組 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 以程式設計方式存取目錄，並在您自己的平台上顯示產品和定價資訊。本節說明如何使用 探索 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>

使用 `GetListing`或 `GetProduct` 顯示完整的產品詳細資訊、媒體和評論。當您需要清單概觀，包括徽章、類別和定價摘要`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`用於摘要資料，並只在使用者導覽至特定產品時呼叫詳細資訊 APIs (`GetProduct`、`GetOffer`、`GetOfferTerms`)。

**注意**  
Discovery API 支援 上的所有產品類型 AWS Marketplace，包括 SaaS、AI 代理器和工具、AMI、容器和機器學習模型。您的界面可以顯示目錄的完整廣度。