Get the support terms of an agreement using an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Get the support terms of an agreement using an AWS SDK

The following code examples show how to get the support terms of an agreement.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library repository.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package com.example.awsmarketplace.agreementapi; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.SupportTerm; import java.util.ArrayList; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsSupportTerm { /* * Obtain the support and refund policy I have provided to the customer */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<SupportTerm> supportTerms = getSupportTerms(agreementId); ReferenceCodesUtils.formatOutput(supportTerms); } public static List<SupportTerm> getSupportTerms(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); GetAgreementTermsRequest getAgreementTermsRequest = GetAgreementTermsRequest.builder().agreementId(agreementId) .build(); GetAgreementTermsResponse getAgreementTermsResponse = marketplaceAgreementClient.getAgreementTerms(getAgreementTermsRequest); List<SupportTerm> supportTerms = new ArrayList<>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.supportTerm() != null) { supportTerms.add(acceptedTerm.supportTerm()); } } return supportTerms; } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library repository.

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Obtain the support and refund policy I have provided to the customer for an agreement AG-19 Example Usage: python3 get_agreement_support_terms.py --agreement-id <agreement-id> """ import argparse import logging import boto3 import utils.helpers as helper from botocore.exceptions import ClientError logger = logging.getLogger(__name__) mp_client = boto3.client("marketplace-agreement") def get_agreement_terms(agreement_id): try: agreement = mp_client.get_agreement_terms(agreementId=agreement_id) return agreement except ClientError as e: if e.response["Error"]["Code"] == "ResourceNotFoundException": logger.error("Agreement with ID %s not found.", agreement_id) else: logger.error("Unexpected error: %s", e) return None if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "--agreement-id", "-aid", help="Provide agreement ID to describe agreement status", required=True, ) args = parser.parse_args() agreement = get_agreement_terms(agreement_id=args.agreement_id) if agreement is not None: support_found = False for term in agreement["acceptedTerms"]: if "supportTerm" in term.keys(): helper.pretty_print_datetime(term) support_found = True if not support_found: print(f"No support term found for agreement: {args.agreement_id}")
  • For API details, see GetAgreementTerms in AWS SDK for Python (Boto3) API Reference.