Get financial details from 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 financial details from an agreement using an AWS SDK

The following code examples show how to get financial details from 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 static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; 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.DescribeAgreementRequest; import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementResponse; public class GetAgreementFinancialDetails { /* * Obtain financial details, such as Total Contract Value of the agreement from a given agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; String totalContractValue = getTotalContractValue(agreementId); System.out.println("Total Contract Value is " + totalContractValue); } public static String getTotalContractValue(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeAgreementRequest describeAgreementRequest = DescribeAgreementRequest.builder() .agreementId(agreementId) .build(); DescribeAgreementResponse describeAgreementResponse = marketplaceAgreementClient.describeAgreement(describeAgreementRequest); String totalContractValue = "N/A"; if ( describeAgreementResponse.estimatedCharges() != null ) { totalContractValue = describeAgreementResponse.estimatedCharges().agreementValue() + " " + describeAgreementResponse.estimatedCharges().currencyCode(); } return totalContractValue; } }
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 financial details, such as Total Contract Value of the agreementfrom a given agreement AG-14 Example Usage: python3 get_agreement_financial_details.py --agreement-id <agreement-id> """ import argparse import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) mp_client = boto3.client("marketplace-agreement") def get_agreement_information(agreement_id): try: agreement = mp_client.describe_agreement(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_information(args.agreement_id) if agreement is not None: print(f"Agreement Id: {args.agreement_id}") print( f"Agreement Value: {agreement['estimatedCharges']['currencyCode']} {agreement['estimatedCharges']['agreementValue']}" ) else: print(f"Agreement with ID {args.agreement_id} is not found")
  • For API details, see DescribeAgreement in AWS SDK for Python (Boto3) API Reference.