使用 a AWS SDK 依優惠 ID 搜尋協議 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 a AWS SDK 依優惠 ID 搜尋協議

下列程式碼範例示範如何依優惠 ID 搜尋協議。

Python
SDK for Python (Boto3)
注意

還有更多 on GitHub。尋找完整的範例,並了解如何在 AWS Marketplace API 參考程式碼庫儲存庫中設定和執行。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to use the AWS SDK for Python (Boto3) to search for agreements by offer id AG-0 """ import logging import boto3 import utils.helpers as helper from botocore.exceptions import ClientError # offer id to search by offerId = "1111111111111111111111111" MAX_PAGE_RESULTS = 10 logger = logging.getLogger(__name__) def get_agreements(mp_client): AgreementSummaryList = [] partyTypes = ["Proposer"] for value in partyTypes: try: agreement = mp_client.search_agreements( catalog="AWSMarketplace", maxResults=MAX_PAGE_RESULTS, filters=[ {"name": "PartyType", "values": [value]}, {"name": "OfferId", "values": [offerId]}, {"name": "AgreementType", "values": ["PurchaseAgreement"]}, ], ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise AgreementSummaryList.extend(agreement["agreementViewSummaries"]) while "nextToken" in agreement and agreement["nextToken"] is not None: try: agreement = mp_client.search_agreements( catalog="AWSMarketplace", maxResults=MAX_PAGE_RESULTS, nextToken=agreement["nextToken"], filters=[ {"name": "PartyType", "values": [value]}, {"name": "OfferId", "values": [offerId]}, {"name": "AgreementType", "values": ["PurchaseAgreement"]}, ], ) except ClientError as e: logger.error("Could not complete search_agreements request.") raise AgreementSummaryList.extend(agreement["agreementViewSummaries"]) return AgreementSummaryList def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Looking for an agreement by offer id.") print("-" * 88) mp_client = boto3.client("marketplace-agreement") helper.pretty_print_datetime(get_agreements(mp_client)) if __name__ == "__main__": usage_demo()
  • 如需 API 詳細資訊,請參閱 SearchAgreements AWS SDK for Python (Boto3) Word 參考中的 API