View a markdown version of this page

使用目录数据构建接口 - AWS Marketplace

AWS Marketplace API 参考已重组。有关支持的 API 操作的更多信息,请参阅 AWS Marketplace API 参考

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

使用目录数据构建接口

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

架构概述

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

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

  2. 商品详情页面 — 致电GetListingGetProduct展示完整的商品详情、媒体和评论。

  3. 定价显示 — 致电ListPurchaseOptionsGetOffer、和GetOfferTerms以显示定价选项。

打造浏览体验

用于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']}")

创建商品详情页面

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 }

显示定价信息

使用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

最佳实践

  • 缓存响应-产品和定价数据不经常更改。将 API 响应缓存 15—60 分钟,以减少 API 调用并缩短页面加载时间。

  • 处理分页-nextToken 用于检索分页操作的所有结果。分页令牌将在 24 小时后过期。

  • 实现重试逻辑-对 ThrottlingException (HTTP 429) 响应使用指数退避。

  • 显示归因 — 在您的平台上显示 AWS Marketplace 数据时,请遵循AWS 商标指南

  • 尽量减少 API 调用-SearchListings 用于摘要数据GetProduct,并且仅在用户导航到特定产品时使用通话详情 API (GetOffer、、GetOfferTerms)。

注意

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