AWS Marketplace Agreement API examples using SDK for Java 2.x
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Java 2.x with AWS Marketplace Agreement API.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Agreements
The following code example shows how to accept an agreement cancellation request initiated by the seller.
- 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. package com.example.awsmarketplace.agreementapi.buyer.agreementCancellation; 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.AcceptAgreementCancellationRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementCancellationRequestResponse; public class AcceptAgreementCancellationRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; public static void main(String[] args) { acceptAgreementCancellationRequest(); } private static void acceptAgreementCancellationRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); AcceptAgreementCancellationRequestRequest request = AcceptAgreementCancellationRequestRequest.builder() .agreementId(AGREEMENT_ID) .agreementCancellationRequestId(AGREEMENT_CANCELLATION_REQUEST_ID) .build(); AcceptAgreementCancellationRequestResponse response = marketplaceAgreementClient.acceptAgreementCancellationRequest(request); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Cancellation Request ID: " + response.agreementCancellationRequestId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Description: " + response.description()); System.out.println("Reason Code: " + response.reasonCodeAsString()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see AcceptAgreementCancellationRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to accept an agreement payment request initiated by the seller.
- 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. package com.example.awsmarketplace.agreementapi.buyer.paymentRequest; 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.AcceptAgreementPaymentRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementPaymentRequestResponse; public class AcceptAgreementPaymentRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; private static final String PURCHASE_ORDER_REFERENCE = "<PURCHASE ORDER REFERENCE HERE>"; public static void main(String[] args) { acceptAgreementPaymentRequest(); } private static void acceptAgreementPaymentRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); AcceptAgreementPaymentRequestRequest request = AcceptAgreementPaymentRequestRequest.builder() .agreementId(AGREEMENT_ID) .paymentRequestId(PAYMENT_REQUEST_ID) .purchaseOrderReference(PURCHASE_ORDER_REFERENCE) .build(); AcceptAgreementPaymentRequestResponse response = marketplaceAgreementClient.acceptAgreementPaymentRequest(request); System.out.println("Payment Request ID: " + response.paymentRequestId()); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Name: " + response.name()); System.out.println("Charge Amount: " + response.chargeAmount()); System.out.println("Currency Code: " + response.currencyCode()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see AcceptAgreementPaymentRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to amend a SaaS contract agreement to add or update its renewal term.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RenewalTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS agreement with CONTRACT pricing model and then turn on * the auto-renewal setting using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to a SaaS product using a public offer that supports * auto-renewal. After acceptance, the buyer decides to amend the agreement to enable * auto-renewal via the RenewalTerm configuration. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement (e.g., {@code P1M} for 1 month).</li> * <li>{@code DIMENSION_1_KEY} — the dimension key defined in the offer.</li> * </ul> */ public class AmendSaaSContractRenewalTerm { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P1M" for 1 month, "P12M" for 1 year). private static final String SELECTOR_VALUE = "<your-selector-value>"; // The dimension key defined in your offer. private static final String DIMENSION_1_KEY = "<your-dimension-key>"; // Quantity for the dimension. private static final int DIMENSION_1_VALUE = 1; // Term ID for the RenewalTerm in your offer. private static final String RENEWAL_TERM_ID = "<your-renewal-term-id>"; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the SupportTerm in your offer. private static final String SUPPORT_TERM_ID = "<your-support-term-id>"; public static void main(String[] args) { amendSaaSContractAgreementRenewalTerm(); } /** * Full end-to-end flow: * 1. Create a SaaS agreement with CONTRACT pricing model with auto-renewal disabled. * 2. Wait for entitlements to become active. * 3. Amend the agreement to enable auto-renewal. */ private static void amendSaaSContractAgreementRenewalTerm() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build()) .build())) .build(); // Initial agreement: auto-renewal disabled. RequestedTerm renewalTerm = RequestedTerm.builder() .id(RENEWAL_TERM_ID) .configuration(RequestedTermConfiguration.fromRenewalTermConfiguration( RenewalTermConfiguration.builder() .enableAutoRenew(false) .build())) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm supportTerm = RequestedTerm.builder().id(SUPPORT_TERM_ID).build(); // --- Create and accept the initial SaaS agreement request with CONTRACT pricing model --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, renewalTerm, legalTerm, supportTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); // Wait for entitlements to become active before amending. System.out.println("Waiting for entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, acceptAgreementRequestResponse.agreementId()); System.out.println("Entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Amend: enable auto-renewal --- RequestedTerm renewalTermAmended = RequestedTerm.builder() .id(RENEWAL_TERM_ID) .configuration(RequestedTermConfiguration.fromRenewalTermConfiguration( RenewalTermConfiguration.builder() .enableAutoRenew(true) .build())) .build(); // Use Intent.AMEND and sourceAgreementIdentifier to target the existing agreement. CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.AMEND) .requestedTerms(configurableUpfrontPricingTerm, renewalTermAmended, legalTerm, supportTerm) .sourceAgreementIdentifier(acceptAgreementRequestResponse.agreementId()) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Amend agreement request created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); System.out.println("Amendment accepted. Auto-renewal enabled. New AgreementId: " + aarResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to amend an AMI agreement with ConfigurableUpfrontPricingTerm by updating dimension quantity for usage pricing model.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import utils.AgreementApiUtils; /** * Demonstrates how to create an AMI agreement with ConfigurableUpfrontPricingTerm and then amend the dimension quantity * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: An AMI product with USAGE pricing requires two agreements: * <ol> * <li>An agreement with <b>usageBasedPricingTerm (UBPT)</b> — accepted first to establish the base agreement.</li> * <li>An agreement with <b>configurableUpfrontPricingTerm (CUPT)</b> — accepted after the UBPT agreement entitlements are active.</li> * </ol> * Once both agreement entitlements are available, this sample shows how to <b>amend</b> the agreement * with configurableUpfrontPricingTerm (CUPT) to increase the dimension quantity. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement * (e.g., {@code P365D} for one year).</li> * <li>{@code DIMENSION_1_KEY} — the dimension key defined in the offer (e.g., instance type).</li> * <li>{@code DIMENSION_1_VALUE} — initial quantity; {@code NEW_DIMENSION_1_VALUE} — amended quantity.</li> * </ul> */ public class AmendAmiConfigurableUpfrontPricingTermForUsagePricingModel { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P365D" for 365 days). private static final String SELECTOR_VALUE = "<your-selector-value>"; // The dimension key defined in your offer (e.g., an EC2 instance type like "c6gn.medium"). private static final String DIMENSION_1_KEY = "<your-dimension-key>"; // Initial quantity for the dimension. private static final int DIMENSION_1_VALUE = 1; // Term ID for the UsageBasedPricingTerm in your offer. private static final String USAGE_TERM_ID = "<your-usage-term-id>"; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in your offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // New quantity to use when amending the dimension of CUPT. private static final int NEW_DIMENSION_1_VALUE = 5; public static void main(String[] args) { amendAmiCUPTAgreement(); } /** * Full end-to-end flow: * 1. Create and accept an agreement request with usageBasedPricingTerm. * 2. Wait for entitlements to become active, then create and accept an agreement request with configurableUpfrontPricingTerm (CUPT). * 3. Wait for CUPT entitlements to become active, then amend the dimension quantity. */ private static void amendAmiCUPTAgreement() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm usageTerm = RequestedTerm.builder() .id(USAGE_TERM_ID) .build(); RequestedTerm legalTerm = RequestedTerm.builder() .id(LEGAL_TERM_ID) .build(); RequestedTerm validityTerm = RequestedTerm.builder() .id(VALIDITY_TERM_ID) .build(); // --- Agreement with UBPT --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(usageTerm, legalTerm, validityTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with UBPT accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); // Wait for entitlements to become active before creating the agreement with CUPT. System.out.println("Waiting for UBPT agreement entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, acceptAgreementRequestResponse.agreementId()); System.out.println("UBPT agreement entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Agreement with configurableUpfrontPricingTerm (CUPT) --- RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build()) .build())) .build(); CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, legalTerm, validityTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Agreement request with CUPT created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); final String cuptAgreementId = aarResponse.agreementId(); System.out.println("Agreement request with CUPT accepted. AgreementId: " + cuptAgreementId); // Wait for entitlements to become active before amending. System.out.println("Waiting for CUPT agreement entitlements to become active..."); GetAgreementEntitlementsResponse cuptEntitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, cuptAgreementId); System.out.println("CUPT agreement entitlements are now active."); AgreementApiUtils.formatOutput(cuptEntitlementsResponse); // --- Amend Agreement with CUPT --- // Increase the dimension quantity using Intent.AMEND and sourceAgreementIdentifier. RequestedTerm newConfig = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(NEW_DIMENSION_1_VALUE) // Increase quantity for this dimension key .build()) .build())) .build(); CreateAgreementRequestRequest carAmendRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.AMEND) .requestedTerms(newConfig, legalTerm, validityTerm) .sourceAgreementIdentifier(cuptAgreementId) .build(); CreateAgreementRequestResponse carAmendResponse = marketplaceAgreementClient.createAgreementRequest(carAmendRequest); System.out.println("Amendment of CUPT agreement request created. AgreementRequestId: " + carAmendResponse.agreementRequestId()); AcceptAgreementRequestRequest aarAmendRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carAmendResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarAmendResponse = marketplaceAgreementClient.acceptAgreementRequest(aarAmendRequest); System.out.println("Amendment accepted. New AgreementId: " + aarAmendResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to create a new AMI free trial agreement.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to create an AMI Free Trial agreement * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to an AMI product that offers a free trial period. * The free trial includes a FreeTrialPricingTerm alongside a UsageBasedPricingTerm. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * </ul> */ public class NewAmiFreeTrial { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in your offer. private static final String FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the UsageBasedPricingTerm in your offer (applies after the trial ends). private static final String USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the SupportTerm in your offer. private static final String SUPPORT_TERM_ID = "<your-support-term-id>"; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; public static void main(String[] args) { createAndAcceptAmiFreeTrialAgreementRequest(); } /** * Creates an AMI Free Trial agreement. * The FreeTrialPricingTerm grants access at no cost for the trial period. * The UsageBasedPricingTerm defines the charges that apply once the trial ends. */ private static void createAndAcceptAmiFreeTrialAgreementRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm freeTrialPricingTerm = RequestedTerm.builder() .id(FREE_TRIAL_PRICING_TERM_ID) .build(); RequestedTerm usageBasedPricingTerm = RequestedTerm.builder() .id(USAGE_BASED_PRICING_TERM_ID) .build(); RequestedTerm supportTerm = RequestedTerm.builder() .id(SUPPORT_TERM_ID) .build(); RequestedTerm legalTerm = RequestedTerm.builder() .id(LEGAL_TERM_ID) .build(); CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(freeTrialPricingTerm, usageBasedPricingTerm, supportTerm, legalTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to create a new SaaS contract agreement with upfront payment.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.TaxConfiguration; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS agreement with CONTRACT pricing model with upfront payment * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to a SaaS product using a ConfigurableUpfrontPricingTerm, * selecting an agreement duration and specifying quantities for multiple dimensions. * Tax estimation is enabled at the time of agreement creation. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement (e.g., {@code P12M} for 12 months).</li> * <li>{@code DIMENSION_1_KEY}, {@code DIMENSION_2_KEY} — dimension keys defined in the offer.</li> * <li>{@code DIMENSION_1_VALUE}, {@code DIMENSION_2_VALUE} — quantities for each dimension.</li> * </ul> */ public class NewSaaSContractWithUpfrontPayment { // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P12M" for 12 months). private static final String SELECTOR_VALUE = "<your-selector-value>"; // First dimension key and quantity defined in your offer. private static final String DIMENSION_1_KEY = "<your-dimension-1-key>"; private static final int DIMENSION_1_VALUE = 10; // Second dimension key and quantity defined in your offer. private static final String DIMENSION_2_KEY = "<your-dimension-2-key>"; private static final int DIMENSION_2_VALUE = 20; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Tax estimation setting: "ENABLED" to include estimated taxes in the agreement. private static final String TAX_ESTIMATION = "ENABLED"; public static void main(String[] args) { createSaaSContractAgreement(); } /** * Creates a SaaS agreement with CONTRACT pricing model with configurable upfront pricing * for multiple dimensions and tax estimation. */ private static void createSaaSContractAgreement() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build(), Dimension.builder() .dimensionKey(DIMENSION_2_KEY) .dimensionValue(DIMENSION_2_VALUE) .build()) .build())) .build(); RequestedTerm legalTerm = RequestedTerm.builder() .id(LEGAL_TERM_ID) .build(); CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, legalTerm) .taxConfiguration(TaxConfiguration.builder().taxEstimation(TAX_ESTIMATION).build()) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("SaaS agreement request with CONTRACT pricing model accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get all agreement IDs.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAllAgreementsIds { /* * Get all purchase agreements ids for your PartyType (Proposer, or Acceptor) * Depend on the number of agreements in your account, this code may take some time to finish. */ public static void main(String[] args) { List<String> agreementIds = getAllAgreementIds(); ReferenceCodesUtils.formatOutput(agreementIds); } public static List<String> getAllAgreementIds() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. // Change to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. Filter partyType = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementType = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); List<Filter> searchFilters = new ArrayList<Filter>(); searchFilters.addAll(Arrays.asList(partyType, agreementType)); // Save all results in a list array List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(searchFilters) .build(); SearchAgreementsResponse searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); while (searchAgreementsResponse.nextToken() != null && searchAgreementsResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .nextToken(searchAgreementsResponse.nextToken()) .filters(searchFilters) .build(); searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); } List<String> agreementIds = new ArrayList<String>(); for (AgreementViewSummary summary : agreementSummaryList) { agreementIds.add(summary.agreementId()); } return agreementIds; } }-
For API details, see SearchAgreements in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get all agreements.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAllAgreements { /* * Get all purchase agreements for your PartyType (Proposer, or Acceptor) * Depend on the number of agreements in your account, this code may take some time to finish. */ public static void main(String[] args) { List<AgreementViewSummary> agreementSummaryList = getAllAgreements(); ReferenceCodesUtils.formatOutput(agreementSummaryList); } public static List<AgreementViewSummary> getAllAgreements() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. // Change to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. Filter partyType = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_ACCEPTOR).build(); Filter agreementType = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); List<Filter> searchFilters = new ArrayList<Filter>(); searchFilters.addAll(Arrays.asList(partyType, agreementType)); // Save all results in a list array List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(searchFilters) .build(); SearchAgreementsResponse searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); while (searchAgreementsResponse.nextToken() != null && searchAgreementsResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .nextToken(searchAgreementsResponse.nextToken()) .filters(searchFilters).build(); searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); } return agreementSummaryList; } }-
For API details, see SearchAgreements in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get customer ID from an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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 GetAgreementCustomerInfo { /* * Obtain metadata about the customer who created the agreement, such as the customer's AWS Account ID */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; DescribeAgreementResponse describeAgreementResponse = getDescribeAgreementResponse(agreementId); System.out.println("Customer's AWS Account ID is " + describeAgreementResponse.acceptor().accountId()); } public static DescribeAgreementResponse getDescribeAgreementResponse(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); return describeAgreementResponse; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get details of a specific agreement cancellation request.
- 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. package com.example.awsmarketplace.agreementapi.buyer.agreementCancellation; 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.GetAgreementCancellationRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementCancellationRequestResponse; public class GetAgreementCancellationRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; public static void main(String[] args) { getAgreementCancellationRequest(); } private static void getAgreementCancellationRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); GetAgreementCancellationRequestRequest request = GetAgreementCancellationRequestRequest.builder() .agreementId(AGREEMENT_ID) .agreementCancellationRequestId(AGREEMENT_CANCELLATION_REQUEST_ID) .build(); GetAgreementCancellationRequestResponse response = marketplaceAgreementClient.getAgreementCancellationRequest(request); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Cancellation Request ID: " + response.agreementCancellationRequestId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Status Message: " + response.statusMessage()); System.out.println("Reason Code: " + response.reasonCodeAsString()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see GetAgreementCancellationRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get details of a specific agreement payment request.
- 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. package com.example.awsmarketplace.agreementapi.buyer.paymentRequest; 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.GetAgreementPaymentRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementPaymentRequestResponse; public class GetAgreementPaymentRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; public static void main(String[] args) { getAgreementPaymentRequest(); } private static void getAgreementPaymentRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); GetAgreementPaymentRequestRequest request = GetAgreementPaymentRequestRequest.builder() .agreementId(AGREEMENT_ID) .paymentRequestId(PAYMENT_REQUEST_ID) .build(); GetAgreementPaymentRequestResponse response = marketplaceAgreementClient.getAgreementPaymentRequest(request); System.out.println("Payment Request ID: " + response.paymentRequestId()); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Status Message: " + response.statusMessage()); System.out.println("Name: " + response.name()); System.out.println("Charge ID: " + response.chargeId()); System.out.println("Charge Amount: " + response.chargeAmount()); System.out.println("Currency Code: " + response.currencyCode()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see GetAgreementPaymentRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get financial details from an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get free trial details from an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.FreeTrialPricingTerm; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import java.util.ArrayList; import java.util.List; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsFreeTrialDetails { /* * Obtain the details from an agreement of a free trial I have provided to the customer */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<FreeTrialPricingTerm> freeTrialPricingTerms = getFreeTrialPricingTerms(agreementId); ReferenceCodesUtils.formatOutput(freeTrialPricingTerms); } public static List<FreeTrialPricingTerm> getFreeTrialPricingTerms(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<FreeTrialPricingTerm> freeTrialPricingTerms = new ArrayList<FreeTrialPricingTerm>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.freeTrialPricingTerm() != null) { freeTrialPricingTerms.add(acceptedTerm.freeTrialPricingTerm()); } } return freeTrialPricingTerms; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get information about an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; 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 DescribeAgreement { public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; DescribeAgreementResponse describeAgreementResponse = getResponse(agreementId); ReferenceCodesUtils.formatOutput(describeAgreementResponse); } public static DescribeAgreementResponse getResponse(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); return describeAgreementResponse; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get product and offer details from an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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; import software.amazon.awssdk.services.marketplaceagreement.model.Resource; import java.util.ArrayList; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityRequest; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityResponse; public class GetProductAndOfferDetailFromAgreement { public static void main(String[] args) { // call Agreement API to get offer and product information for the agreement String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<DescribeEntityResponse> entityResponseList = getEntities(agreementId); for (DescribeEntityResponse response : entityResponseList) { ReferenceCodesUtils.formatOutput(response); } } public static List<DescribeEntityResponse> getEntities(String agreementId) { List<DescribeEntityResponse> entityResponseList = new ArrayList<DescribeEntityResponse> (); MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeAgreementRequest describeAgreementRequest = DescribeAgreementRequest.builder() .agreementId(agreementId) .build(); DescribeAgreementResponse describeAgreementResponse = marketplaceAgreementClient.describeAgreement(describeAgreementRequest); // get offer id for the given agreement String offerId = describeAgreementResponse.proposalSummary().offerId(); // get all the product ids for this agreement List<String> productIds = new ArrayList<String>(); for (Resource resource : describeAgreementResponse.proposalSummary().resources()) { productIds.add(resource.id()); } // call Catalog API to get the details of the offer and products MarketplaceCatalogClient marketplaceCatalogClient = MarketplaceCatalogClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeEntityRequest describeEntityRequest = DescribeEntityRequest.builder() .catalog(AWS_MP_CATALOG) .entityId(offerId).build(); DescribeEntityResponse describeEntityResponse = marketplaceCatalogClient.describeEntity(describeEntityRequest); entityResponseList.add(describeEntityResponse); for (String productId : productIds) { describeEntityRequest = DescribeEntityRequest.builder() .catalog(AWS_MP_CATALOG) .entityId(productId).build(); describeEntityResponse = marketplaceCatalogClient.describeEntity(describeEntityRequest); System.out.println("Print details for product " + productId); entityResponseList.add(describeEntityResponse); } return entityResponseList; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the EULA of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.DocumentItem; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; 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 GetAgreementTermsEula { /* * Obtain the EULA I have entered into with my customer via the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<DocumentItem> legalEulaArray = getLegalEula(agreementId); ReferenceCodesUtils.formatOutput(legalEulaArray); } public static List<DocumentItem> getLegalEula(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<DocumentItem> legalEulaArray = new ArrayList<>(); getAgreementTermsResponse.acceptedTerms().stream() .filter(acceptedTerm -> acceptedTerm.legalTerm() != null && acceptedTerm.legalTerm().hasDocuments()) .flatMap(acceptedTerm -> acceptedTerm.legalTerm().documents().stream()) .filter(docItem -> docItem.type() != null) .forEach(legalEulaArray::add); return legalEulaArray; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the auto renewal terms of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AcceptedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; public class GetAgreementAutoRenewal { /* * Obtain the auto-renewal status of the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; String autoRenewal = getAutoRenewal(agreementId); System.out.println("Auto-Renewal status is " + autoRenewal); } public static String getAutoRenewal(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); String autoRenewal = "No Auto Renewal"; for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.renewalTerm() != null && acceptedTerm.renewalTerm().configuration() != null && acceptedTerm.renewalTerm().configuration().enableAutoRenew() != null) { autoRenewal = String.valueOf(acceptedTerm.renewalTerm().configuration().enableAutoRenew().booleanValue()); break; } } return autoRenewal; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the dimensions purchased in an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; 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 GetAgreementTermsDimensionPurchased { /* * Obtain the dimensions the buyer has purchased from me via the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<String> dimensionKeys = getDimensionKeys(agreementId); ReferenceCodesUtils.formatOutput(dimensionKeys); } public static List<String> getDimensionKeys(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<String> dimensionKeys = new ArrayList<String>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.configurableUpfrontPricingTerm() != null) { if (acceptedTerm.configurableUpfrontPricingTerm().configuration().selectorValue() != null) { List<Dimension> dimensions = acceptedTerm.configurableUpfrontPricingTerm().configuration().dimensions(); for (Dimension dimension : dimensions) { dimensionKeys.add(dimension.dimensionKey()); } } } } return dimensionKeys; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the instances of each dimension purchased in an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsDimensionInstances { /* * get instances of each dimension that buyer has purchased in the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; Map<String, List<Dimension>> dimensionMap = getDimensions(agreementId); ReferenceCodesUtils.formatOutput(dimensionMap); } public static Map<String, List<Dimension>> getDimensions(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); Map<String, List<Dimension>> dimensionMap = new HashMap<String, List<Dimension>>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { List<Dimension> dimensionsList = new ArrayList<Dimension>(); if (acceptedTerm.configurableUpfrontPricingTerm() != null) { String selectorValue = ""; if (acceptedTerm.configurableUpfrontPricingTerm().configuration() != null) { if (acceptedTerm.configurableUpfrontPricingTerm().configuration().selectorValue() != null) { selectorValue = acceptedTerm.configurableUpfrontPricingTerm().configuration().selectorValue(); } if (acceptedTerm.configurableUpfrontPricingTerm().configuration().hasDimensions()) { dimensionsList = acceptedTerm.configurableUpfrontPricingTerm().configuration().dimensions(); } } if (selectorValue.length() > 0) { dimensionMap.put(selectorValue, dimensionsList); } } } return dimensionMap; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the payment schedule of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.PaymentScheduleTerm; import software.amazon.awssdk.services.marketplaceagreement.model.ScheduleItem; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsPaymentSchedule { /* * Obtain the payment schedule I have agreed to with the agreement, including the invoice date and invoice amount */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<Map<String, Object>> paymentScheduleArray = getPaymentSchedules(agreementId); ReferenceCodesUtils.formatOutput(paymentScheduleArray); } public static List<Map<String, Object>> getPaymentSchedules(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<Map<String, Object>> paymentScheduleArray = new ArrayList<>(); String currencyCode = ""; for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { if (acceptedTerm.paymentScheduleTerm() != null) { PaymentScheduleTerm paymentScheduleTerm = acceptedTerm.paymentScheduleTerm(); if (paymentScheduleTerm.currencyCode() != null) { currencyCode = paymentScheduleTerm.currencyCode(); } if (paymentScheduleTerm.hasSchedule()) { for (ScheduleItem schedule : paymentScheduleTerm.schedule()) { if (schedule.chargeDate() != null) { String chargeDate = schedule.chargeDate().toString(); String chargeAmount = schedule.chargeAmount(); Map<String, Object> scheduleMap = new HashMap<>(); scheduleMap.put(ATTRIBUTE_CURRENCY_CODE, currencyCode); scheduleMap.put(ATTRIBUTE_CHARGE_DATE, chargeDate); scheduleMap.put(ATTRIBUTE_CHARGE_AMOUNT, chargeAmount); paymentScheduleArray.add(scheduleMap); } } } } } return paymentScheduleArray; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the pricing per dimension in an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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 java.util.ArrayList; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementTermsPricingEachDimension { /* * Obtain pricing per each dimension in the agreement */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<Object> dimensions = getDimensions(agreementId); ReferenceCodesUtils.formatOutput(dimensions); } public static List<Object> getDimensions(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<Object> dimensions = new ArrayList<Object>(); for (AcceptedTerm acceptedTerm : getAgreementTermsResponse.acceptedTerms()) { List<Object> rateInfo = new ArrayList<Object>(); if (acceptedTerm.configurableUpfrontPricingTerm() != null) { if (acceptedTerm.configurableUpfrontPricingTerm().type() != null) { rateInfo.add(acceptedTerm.configurableUpfrontPricingTerm().type()); } if (acceptedTerm.configurableUpfrontPricingTerm().currencyCode() != null) { rateInfo.add(acceptedTerm.configurableUpfrontPricingTerm().currencyCode()); } if (acceptedTerm.configurableUpfrontPricingTerm().hasRateCards()) { rateInfo.add(acceptedTerm.configurableUpfrontPricingTerm().rateCards()); } dimensions.add(rateInfo); } } return dimensions; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the pricing type of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import org.apache.commons.lang3.tuple.Triple; import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityRequest; import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityResponse; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; /* * Obtain the pricing type of the agreement (contract, FPS, metered, free etc.) */ public class GetAgreementPricingType { private static final String FILTER_NAME = "OfferId"; private static final String FILTER_VALUE = OFFER_ID; // Product types private static final String SAAS_PRODUCT = "SaaSProduct"; private static final String AMI_PRODUCT = "AmiProduct"; private static final String ML_PRODUCT = "MachineLearningProduct"; private static final String CONTAINER_PRODUCT = "ContainerProduct"; private static final String DATA_PRODUCT = "DataProduct"; private static final String PROSERVICE_PRODUCT = "ProfessionalServicesProduct"; private static final String AIQ_PRODUCT = "AiqProduct"; // Pricing types private static final String CCP = "CCP"; private static final String ANNUAL = "Annual"; private static final String CONTRACT = "Contract"; private static final String SFT = "SaaS Free Trial"; private static final String HMA = "Hourly and Monthly Agreements"; private static final String HOURLY = "Hourly"; private static final String MONTHLY = "Monthly"; private static final String AFPS = "Annual FPS"; private static final String CFPS = "Contract FPS"; private static final String CCPFPS = "CCP with FPS"; private static final String BYOL = "BYOL"; private static final String FREE = "Free"; private static final String FTH = "Free Trials and Hourly"; // Agreement term pricing types private static final Set<String> LEGAL = Set.of("LegalTerm"); private static final Set<String> CONFIGURABLE_UPFRONT = Set.of("ConfigurableUpfrontPricingTerm"); private static final Set<String> USAGE_BASED = Set.of("UsageBasedPricingTerm"); private static final Set<String> CONFIGURABLE_UPFRONT_AND_USAGE_BASED = Set.of("ConfigurableUpfrontPricingTerm", "UsageBasedPricingTerm"); private static final Set<String> FREE_TRIAL = Set.of("FreeTrialPricingTerm"); private static final Set<String> RECURRING_PAYMENT = Set.of("RecurringPaymentTerm"); private static final Set<String> USAGE_BASED_AND_RECURRING_PAYMENT = Set.of("UsageBasedPricingTerm", "RecurringPaymentTerm"); private static final Set<String> FIXED_UPFRONT_AND_PAYMENT_SCHEDULE = Set.of("FixedUpfrontPricingTerm", "PaymentScheduleTerm"); private static final Set<String> FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED = Set.of("FixedUpfrontPricingTerm", "PaymentScheduleTerm", "UsageBasedPricingTerm"); private static final Set<String> BYOL_PRICING = Set.of("ByolPricingTerm"); private static final Set<String> FREE_TRIAL_AND_USAGE_BASED = Set.of("FreeTrialPricingTerm", "UsageBasedPricingTerm"); private static final List<Set<String>> ALL_AGREEMENT_TERM_TYPES_COMBINATION = Arrays.asList(LEGAL, CONFIGURABLE_UPFRONT, USAGE_BASED, CONFIGURABLE_UPFRONT_AND_USAGE_BASED, FREE_TRIAL, RECURRING_PAYMENT, USAGE_BASED_AND_RECURRING_PAYMENT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED, BYOL_PRICING, FREE_TRIAL_AND_USAGE_BASED); private static MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); private static MarketplaceCatalogClient marketplaceCatalogClient = MarketplaceCatalogClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); /* * Get agreement Pricing Type given product type, agreement term types and offer types if needed */ public static String getPricingType(String productType, Set<String> agreementTermType, Set<String> offerType) { Map<Triple<String, Set<String>, Set<String>>, String> pricingTypes = new HashMap<>(); pricingTypes.put(Triple.of(SAAS_PRODUCT, CONFIGURABLE_UPFRONT_AND_USAGE_BASED, new HashSet<>()), CCP); pricingTypes.put(Triple.of(DATA_PRODUCT, CONFIGURABLE_UPFRONT_AND_USAGE_BASED, new HashSet<>()), CCP); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, CONFIGURABLE_UPFRONT, CONFIGURABLE_UPFRONT_AND_USAGE_BASED), ANNUAL); pricingTypes.put(Triple.of(AMI_PRODUCT, CONFIGURABLE_UPFRONT, CONFIGURABLE_UPFRONT_AND_USAGE_BASED), ANNUAL); pricingTypes.put(Triple.of(ML_PRODUCT, CONFIGURABLE_UPFRONT, CONFIGURABLE_UPFRONT_AND_USAGE_BASED), ANNUAL); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, CONFIGURABLE_UPFRONT, CONFIGURABLE_UPFRONT), CONTRACT); pricingTypes.put(Triple.of(AMI_PRODUCT, CONFIGURABLE_UPFRONT, CONFIGURABLE_UPFRONT), CONTRACT); pricingTypes.put(Triple.of(SAAS_PRODUCT, CONFIGURABLE_UPFRONT, new HashSet<>()), CONTRACT); pricingTypes.put(Triple.of(DATA_PRODUCT, CONFIGURABLE_UPFRONT, new HashSet<>()), CONTRACT); pricingTypes.put(Triple.of(AIQ_PRODUCT, CONFIGURABLE_UPFRONT, new HashSet<>()), CONTRACT); pricingTypes.put(Triple.of(PROSERVICE_PRODUCT, CONFIGURABLE_UPFRONT, new HashSet<>()), CONTRACT); pricingTypes.put(Triple.of(SAAS_PRODUCT, FREE_TRIAL, new HashSet<>()), SFT); pricingTypes.put(Triple.of(AMI_PRODUCT, USAGE_BASED_AND_RECURRING_PAYMENT, new HashSet<>()), HMA); pricingTypes.put(Triple.of(SAAS_PRODUCT, USAGE_BASED, new HashSet<>()), HOURLY); pricingTypes.put(Triple.of(AMI_PRODUCT, USAGE_BASED, new HashSet<>()), HOURLY); pricingTypes.put(Triple.of(ML_PRODUCT, USAGE_BASED, new HashSet<>()), HOURLY); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, RECURRING_PAYMENT, new HashSet<>()), MONTHLY); pricingTypes.put(Triple.of(AMI_PRODUCT, RECURRING_PAYMENT, new HashSet<>()), MONTHLY); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED), AFPS); pricingTypes.put(Triple.of(AMI_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED), AFPS); pricingTypes.put(Triple.of(ML_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), AFPS); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), CFPS); pricingTypes.put(Triple.of(AMI_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE), CFPS); pricingTypes.put(Triple.of(SAAS_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), CFPS); pricingTypes.put(Triple.of(DATA_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), CFPS); pricingTypes.put(Triple.of(AIQ_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), CFPS); pricingTypes.put(Triple.of(PROSERVICE_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE, new HashSet<>()), CFPS); pricingTypes.put(Triple.of(SAAS_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED, new HashSet<>()), CCPFPS); pricingTypes.put(Triple.of(DATA_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED, new HashSet<>()), CCPFPS); pricingTypes.put(Triple.of(AIQ_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED, new HashSet<>()), CCPFPS); pricingTypes.put(Triple.of(PROSERVICE_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE_AND_USAGE_BASED, new HashSet<>()), CCPFPS); pricingTypes.put(Triple.of(AMI_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(SAAS_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(PROSERVICE_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(AIQ_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(ML_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(DATA_PRODUCT, BYOL_PRICING, new HashSet<>()), BYOL); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, LEGAL, new HashSet<>()), FREE); pricingTypes.put(Triple.of(AMI_PRODUCT, FREE_TRIAL_AND_USAGE_BASED, new HashSet<>()), FTH); pricingTypes.put(Triple.of(CONTAINER_PRODUCT, FREE_TRIAL_AND_USAGE_BASED, new HashSet<>()), FTH); pricingTypes.put(Triple.of(ML_PRODUCT, FREE_TRIAL_AND_USAGE_BASED, new HashSet<>()), FTH); Triple<String, Set<String>, Set<String>> key = Triple.of(productType, agreementTermType, offerType); if (pricingTypes.containsKey(key)) { return pricingTypes.get(key); } else { return "Unknown"; } } /* * Given product type and agreement term types, some combinations need to check offer term types as well. */ public static String needToCheckOfferTermsType(String productType, Set<String> agreementTermTypes) { Map<KeyPair, String> offerTermTypes = new HashMap<>(); offerTermTypes.put(new KeyPair(CONTAINER_PRODUCT, CONFIGURABLE_UPFRONT), "Y"); offerTermTypes.put(new KeyPair(AMI_PRODUCT, CONFIGURABLE_UPFRONT), "Y"); offerTermTypes.put(new KeyPair(CONTAINER_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE), "Y"); offerTermTypes.put(new KeyPair(AMI_PRODUCT, FIXED_UPFRONT_AND_PAYMENT_SCHEDULE), "Y"); KeyPair key = new KeyPair(productType, agreementTermTypes); if (offerTermTypes.containsKey(key)) { return offerTermTypes.get(key); } else { return null; } } public static List<AgreementViewSummary> getAgreementsById() { List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. // Change to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. Filter partyType = Filter.builder().name(PARTY_TYPE_FILTER_NAME).values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementType = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME).values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); Filter customizeFilter = Filter.builder().name(FILTER_NAME).values(FILTER_VALUE).build(); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(partyType, agreementType, customizeFilter).build(); SearchAgreementsResponse searchResultResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchResultResponse.agreementViewSummaries()); while (searchResultResponse.nextToken() != null && searchResultResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder().catalog(AWS_MP_CATALOG) .filters(partyType, agreementType).nextToken(searchResultResponse.nextToken()).build(); searchResultResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchResultResponse.agreementViewSummaries()); } return agreementSummaryList; } static class KeyPair { private final String first; private final Set<String> second; public KeyPair(String productType, Set<String> second) { this.first = productType; this.second = second; } @Override public int hashCode() { return Objects.hash(first, second); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; KeyPair other = (KeyPair) obj; return Objects.equals(first, other.first) && Objects.equals(second, other.second); } } /* * Get all the term types for the offer */ public static Set<String> getOfferTermTypes(String offerId) { Set<String> offerTermTypes = new HashSet<String>(); DescribeEntityRequest request = DescribeEntityRequest.builder() .catalog(AWS_MP_CATALOG) .entityId(offerId) .build(); DescribeEntityResponse result = marketplaceCatalogClient.describeEntity(request); String details = result.details(); try { ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(details); JsonNode termsNode = rootNode.get(ATTRIBUTE_TERMS); for (JsonNode termNode : termsNode) { if (termNode.get(ATTRIBUTE_TYPE_ENTITY) != null ) { offerTermTypes.add(termNode.get(ATTRIBUTE_TYPE_ENTITY).asText()); } } } catch (Exception e) { e.printStackTrace(); } return offerTermTypes; } /* * Get all the agreement term types */ public static Set<String> getAgreementTermTypes(GetAgreementTermsResponse agreementTerm) { Set<String> agreementTermTypes = new HashSet<String>(); try { for (AcceptedTerm term : agreementTerm.acceptedTerms()) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode termNode = objectMapper.readTree(getJson(term)); Iterator<Map.Entry<String, JsonNode>> fieldsIterator = termNode.fields(); while (fieldsIterator.hasNext()) { Map.Entry<String, JsonNode> entry = fieldsIterator.next(); JsonNode value = entry.getValue(); if (value.isObject() && value.has(ATTRIBUTE_TYPE_AGREEMENT)) { agreementTermTypes.add(value.get(ATTRIBUTE_TYPE_AGREEMENT).asText()); } } } } catch (Exception e) { e.printStackTrace(); } return agreementTermTypes; } /* * make sure all elements in array2 exist in array1 */ public static boolean allElementsExist(Set<String> array1, Set<String> array2) { for (String element : array2) { boolean found = false; for (String str : array1) { if (element.equals(str)) { found = true; break; } } if (!found) { return false; } } return true; } /* * Find the combinations of the agreement term types for the agreement */ public static Set<String> getMatchedTermTypesCombination(Set<String> agreementTermTypes) { Set<String> matchedCombination = new HashSet<String>(); for (Set<String> element : ALL_AGREEMENT_TERM_TYPES_COMBINATION) { if (allElementsExist(agreementTermTypes, element)) { matchedCombination = element; } } return matchedCombination; } public static void main(String[] args) { List<AgreementViewSummary> agreements = getAgreementsById(); for (AgreementViewSummary summary : agreements) { String pricingType = ""; String agreementId = summary.agreementId(); System.out.println(agreementId); String offerId = summary.proposalSummary().offerId(); //get all pricing term types for the offer in the agreement Set<String> offerTermTypes = getOfferTermTypes(offerId); String productType = summary.proposalSummary().resources().get(0).type(); //get all pricing term types for the agreement GetAgreementTermsRequest getAgreementTermsRequest = GetAgreementTermsRequest.builder().agreementId(agreementId) .build(); GetAgreementTermsResponse getAgreementTermsResponse = marketplaceAgreementClient.getAgreementTerms(getAgreementTermsRequest); Set<String> agreementTermTypes = getAgreementTermTypes(getAgreementTermsResponse); //get matched pricing term type combination set Set<String> agreementMatchedTermType = getMatchedTermTypesCombination(agreementTermTypes); //check to see if this agreement pricing term combination needs additional check on offer pricing terms String needToCheckOfferType = needToCheckOfferTermsType(productType, agreementMatchedTermType); // get the pricing type for the agreement based on the product type, agreement term types and offer term types if needed if (needToCheckOfferType != null) { Set<String> offerMatchedTermType = getMatchedTermTypesCombination(offerTermTypes); pricingType = getPricingType(productType, agreementMatchedTermType, offerMatchedTermType); } else if (agreementMatchedTermType == LEGAL) { pricingType = FREE; } else { pricingType = getPricingType(productType, agreementMatchedTermType, new HashSet()); } System.out.println("Pricing type is " + pricingType); } } private static String getJson(Object result) { String json = ""; try { ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); om.registerModule(new JavaTimeModule()); ObjectWriter ow = om.writer().withDefaultPrettyPrinter(); json = ow.writeValueAsString(result); } catch (JsonProcessingException e) { e.printStackTrace(); } return json; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the product type of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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; import software.amazon.awssdk.services.marketplaceagreement.model.Resource; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import java.util.ArrayList; import java.util.List; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class GetAgreementProductType { /* * Obtain the Product Type of the product the agreement was created on */ public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; List<String> productIds = getProducts(agreementId); ReferenceCodesUtils.formatOutput(productIds); } public static List<String> getProducts(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); List<String> productIds = new ArrayList<String>(); for (Resource resource : describeAgreementResponse.proposalSummary().resources()) { productIds.add(resource.id() + ":" + resource.type()); } return productIds; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the status of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; 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 GetAgreementStatus { public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; DescribeAgreementResponse describeAgreementResponse = getDescribeAgreementResponse(agreementId); System.out.println("Agreement status is " + describeAgreementResponse.status()); } public static DescribeAgreementResponse getDescribeAgreementResponse(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); return describeAgreementResponse; } }-
For API details, see DescribeAgreement in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the support terms of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to get the terms of an agreement.
- 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. package com.example.awsmarketplace.agreementapi.seller; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; 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.GetAgreementTermsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementTermsResponse; public class GetAgreementTerms { public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; GetAgreementTermsResponse getAgreementTermsResponse = getAgreementTermsResponse(agreementId); ReferenceCodesUtils.formatOutput(getAgreementTermsResponse); } public static GetAgreementTermsResponse getAgreementTermsResponse(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); return getAgreementTermsResponse; } }-
For API details, see GetAgreementTerms in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to list agreement cancellation requests for agreements I participate in as acceptor.
- 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. package com.example.awsmarketplace.agreementapi.buyer.agreementCancellation; 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.AgreementCancellationRequestSummary; import software.amazon.awssdk.services.marketplaceagreement.model.ListAgreementCancellationRequestsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.ListAgreementCancellationRequestsResponse; public class ListAgreementCancellationRequests { private static final String PARTY_TYPE = "Proposer"; public static void main(String[] args) { listAgreementCancellationRequests(); } private static void listAgreementCancellationRequests() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); String nextToken = null; do { ListAgreementCancellationRequestsRequest request = ListAgreementCancellationRequestsRequest.builder() .partyType(PARTY_TYPE) .nextToken(nextToken) .build(); ListAgreementCancellationRequestsResponse response = marketplaceAgreementClient.listAgreementCancellationRequests(request); for (AgreementCancellationRequestSummary summary : response.items()) { System.out.println("Cancellation Request ID: " + summary.agreementCancellationRequestId()); System.out.println("Agreement ID: " + summary.agreementId()); System.out.println("Status: " + summary.statusAsString()); System.out.println("Reason Code: " + summary.reasonCodeAsString()); System.out.println("Agreement Type: " + summary.agreementType()); System.out.println("Catalog: " + summary.catalog()); System.out.println("Created At: " + summary.createdAt()); System.out.println("Updated At: " + summary.updatedAt()); System.out.println("---"); } nextToken = response.nextToken(); } while (nextToken != null); } }-
For API details, see ListAgreementCancellationRequests in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to list agreement payment requests for agreements I participate in as acceptor.
- 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. package com.example.awsmarketplace.agreementapi.buyer.paymentRequest; 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.ListAgreementPaymentRequestsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.ListAgreementPaymentRequestsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.PaymentRequestSummary; public class ListAgreementPaymentRequests { private static final String PARTY_TYPE = "Proposer"; public static void main(String[] args) { listAgreementPaymentRequests(); } private static void listAgreementPaymentRequests() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); String nextToken = null; do { ListAgreementPaymentRequestsRequest request = ListAgreementPaymentRequestsRequest.builder() .partyType(PARTY_TYPE) .nextToken(nextToken) .build(); ListAgreementPaymentRequestsResponse response = marketplaceAgreementClient.listAgreementPaymentRequests(request); for (PaymentRequestSummary summary : response.items()) { System.out.println("Payment Request ID: " + summary.paymentRequestId()); System.out.println("Agreement ID: " + summary.agreementId()); System.out.println("Status: " + summary.statusAsString()); System.out.println("Name: " + summary.name()); System.out.println("Charge ID: " + summary.chargeId()); System.out.println("Charge Amount: " + summary.chargeAmount()); System.out.println("Currency Code: " + summary.currencyCode()); System.out.println("Created At: " + summary.createdAt()); System.out.println("Updated At: " + summary.updatedAt()); System.out.println("---"); } nextToken = response.nextToken(); } while (nextToken != null); } }-
For API details, see ListAgreementPaymentRequests in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to reject an agreement cancellation request initiated by the seller.
- 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. package com.example.awsmarketplace.agreementapi.buyer.agreementCancellation; 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.RejectAgreementCancellationRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.RejectAgreementCancellationRequestResponse; public class RejectAgreementCancellationRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; private static final String REJECTION_REASON = "<REJECTION REASON HERE>"; public static void main(String[] args) { rejectAgreementCancellationRequest(); } private static void rejectAgreementCancellationRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RejectAgreementCancellationRequestRequest request = RejectAgreementCancellationRequestRequest.builder() .agreementId(AGREEMENT_ID) .agreementCancellationRequestId(AGREEMENT_CANCELLATION_REQUEST_ID) .rejectionReason(REJECTION_REASON) .build(); RejectAgreementCancellationRequestResponse response = marketplaceAgreementClient.rejectAgreementCancellationRequest(request); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Cancellation Request ID: " + response.agreementCancellationRequestId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Status Message: " + response.statusMessage()); System.out.println("Reason Code: " + response.reasonCodeAsString()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see RejectAgreementCancellationRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to reject an agreement payment request initiated by the seller.
- 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. package com.example.awsmarketplace.agreementapi.buyer.paymentRequest; 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.RejectAgreementPaymentRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.RejectAgreementPaymentRequestResponse; public class RejectAgreementPaymentRequest { private static final String AGREEMENT_ID = "<AGREEMENT ID HERE>"; private static final String PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; private static final String REJECTION_REASON = "<REJECTION REASON HERE>"; public static void main(String[] args) { rejectAgreementPaymentRequest(); } private static void rejectAgreementPaymentRequest() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RejectAgreementPaymentRequestRequest request = RejectAgreementPaymentRequestRequest.builder() .agreementId(AGREEMENT_ID) .paymentRequestId(PAYMENT_REQUEST_ID) .rejectionReason(REJECTION_REASON) .build(); RejectAgreementPaymentRequestResponse response = marketplaceAgreementClient.rejectAgreementPaymentRequest(request); System.out.println("Payment Request ID: " + response.paymentRequestId()); System.out.println("Agreement ID: " + response.agreementId()); System.out.println("Status: " + response.statusAsString()); System.out.println("Status Message: " + response.statusMessage()); System.out.println("Name: " + response.name()); System.out.println("Charge Amount: " + response.chargeAmount()); System.out.println("Currency Code: " + response.currencyCode()); System.out.println("Created At: " + response.createdAt()); System.out.println("Updated At: " + response.updatedAt()); } }-
For API details, see RejectAgreementPaymentRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to replace a SaaS contract agreement with a new agreement-based offer.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to replace an existing SaaS agreement with CONTRACT pricing model with a new * Agreement-Based Offer (ABO) using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer has an active SaaS agreement with CONTRACT pricing model and receives a private * Agreement-Based Offer from the seller. The buyer replaces the existing agreement * with the new ABO offer, which may include updated pricing terms and payment schedule. * * <p>Note: Unlike other Replace samples, this example starts from an already-active * {@code EXISTING_AGREEMENT_ID} rather than creating a new agreement first. Use this * pattern when you already have an agreement ID and want to replace it directly. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code EXISTING_AGREEMENT_ID} — the agreement ID of the active agreement to replace (starts with {@code agmt-}).</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the new ABO offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the new offer's term list.</li> * </ul> */ public class ReplaceSaaSContractWithAgreementBasedOffer { // The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). private static final String EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>"; // The agreementProposalId from the new Agreement-Based Offer. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the LegalTerm in the new offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the FixedUpfrontPricingTerm in the new offer. private static final String FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the new offer. private static final String PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; public static void main(String[] args) { replaceExistingAgreement(); } /** * Replaces an existing SaaS agreement with CONTRACT pricing model with a new Agreement-Based Offer. * Uses Intent.REPLACE with sourceAgreementIdentifier set to the existing agreement ID. */ private static void replaceExistingAgreement() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); RequestedTerm fixedUpfrontPricingTerm = RequestedTerm.builder().id(FIXED_UPFRONT_PRICING_TERM_ID).build(); RequestedTerm paymentScheduleTerm = RequestedTerm.builder().id(PAYMENT_SCHEDULE_TERM_ID).build(); // Replace the agreement with the new offer CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(fixedUpfrontPricingTerm, paymentScheduleTerm, legalTerm, validityTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(EXISTING_AGREEMENT_ID) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement replaced with ABO. New AgreementId: " + acceptAgreementRequestResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to replace a SaaS free trial with a Contract with Consumption Pricing (CCP).
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS free trial agreement and then replace it with a * paid Contract with Consumption Pricing (CCP) offer using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer first starts a free trial on a SaaS product. Once the trial is active, * they decide to convert by replacing it with a paid offer that includes a * FixedUpfrontPricingTerm, PaymentScheduleTerm, and UsageBasedPricingTerm. * * <p>Flow: * <ol> * <li>Create a SaaS free trial agreement with freeTrialPricingTerm.</li> * <li>Wait for freeTrialPricingTerm agreement entitlements to become active.</li> * <li>Replace the free trial agreement with the paid CCP offer using Intent.REPLACE.</li> * </ol> * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the free trial offer.</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the paid CCP offer.</li> * <li>Term IDs (starting with {@code term-}) — found in each offer's term list.</li> * </ul> */ public class ReplaceSaaSFreeTrialWithCCP { // The agreementProposalId from the free trial offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-free-trial-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in the free trial offer. private static final String FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the LegalTerm in the free trial offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the paid CCP offer to convert to. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-ccp-agreement-proposal-identifier>"; // Term ID for the FixedUpfrontPricingTerm in the CCP offer. private static final String FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the CCP offer. private static final String PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; // Term ID for the UsageBasedPricingTerm in the CCP offer. private static final String USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the CCP offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the CCP offer. private static final String NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; public static void main(String[] args) { createSaaSFreeTrialAndReplaceWithCCP(); } /** * Full end-to-end flow: * 1. Create a SaaS free trial agreement with freeTrialPricingTerm. * 2. Wait for freeTrialPricingTerm agreement entitlements to become active. * 3. Replace the free trial agreement with the paid CCP offer. */ private static void createSaaSFreeTrialAndReplaceWithCCP() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm freeTrialPricingTerm = RequestedTerm.builder().id(FREE_TRIAL_PRICING_TERM_ID).build(); // --- Step 1: Agreement with freeTrialPricingTerm --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(freeTrialPricingTerm, legalTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); // Wait for freeTrialPricingTerm agreement entitlements to become active before replacing. System.out.println("Waiting for freeTrialPricingTerm agreement entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, acceptAgreementRequestResponse.agreementId()); System.out.println("freeTrialPricingTerm agreement entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Step 2: Replace Agreement with freeTrialPricingTerm with Paid CCP Offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the free trial agreement. RequestedTerm usageBasedPricingTerm = RequestedTerm.builder().id(USAGE_BASED_PRICING_TERM_ID).build(); RequestedTerm fixedUpfrontPricingTerm = RequestedTerm.builder().id(FIXED_UPFRONT_PRICING_TERM_ID).build(); RequestedTerm paymentScheduleTerm = RequestedTerm.builder().id(PAYMENT_SCHEDULE_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); RequestedTerm newLegalTerm = RequestedTerm.builder().id(NEW_LEGAL_TERM_ID).build(); CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(usageBasedPricingTerm, fixedUpfrontPricingTerm, paymentScheduleTerm, validityTerm, newLegalTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(acceptAgreementRequestResponse.agreementId()) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); System.out.println("Agreement with freeTrialPricingTerm replaced with paid CCP offer. New AgreementId: " + aarResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to replace a SaaS usage-based pricing term and cancel the previous agreement.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.CancelAgreementRequest; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import utils.AgreementApiUtils; /** * Demonstrates how to create a SaaS agreement with usageBasedPricingTerm (UBPT) and then replace it * with a new offer using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer subscribes to a SaaS product with UsageBasedPricingTerm. * The buyer then converts to a different offer by replacing the existing agreement. * * <p>Flow: * <ol> * <li>Create and accept the initial agreement request with UBPT.</li> * <li>Wait for entitlements to become active.</li> * <li>Replace the agreement with a new offer using Intent.REPLACE.</li> * <li>Cancel the new agreement using CancelAgreement.</li> * </ol> * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the initial offer.</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the new offer to replace to.</li> * <li>Term IDs (starting with {@code term-}) — found in each offer's term list.</li> * </ul> */ public class ReplaceSaaSUsageBasedPricingTermAndCancel { // The agreementProposalId from the initial offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the initial offer. private static final String USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the initial offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the initial offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the new offer to replace to. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the new offer. private static final String NEW_USAGE_BASED_PRICING_TERM_ID = "<your-new-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the new offer. private static final String NEW_VALIDITY_TERM_ID = "<your-new-validity-term-id>"; // Term ID for the LegalTerm in the new offer. private static final String NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; public static void main(String[] args) { replaceSaaSUbptAndCancel(); } /** * Full end-to-end flow: * 1. Create and accept the initial agreement request with UsageBasedPricingTerm. * 2. Wait for entitlements to become active. * 3. Replace the agreement with a new offer. * 4. Cancel the new agreement. */ private static void replaceSaaSUbptAndCancel() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm usageBasedPricingTerm = RequestedTerm.builder().id(USAGE_BASED_PRICING_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); // --- Step 1: Create and accept the initial UBPT agreement request --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(usageBasedPricingTerm, validityTerm, legalTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); System.out.println("Agreement request with UBPT accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId()); // Wait for entitlements to become active before replacing. System.out.println("Waiting for entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, acceptAgreementRequestResponse.agreementId()); System.out.println("Entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Step 2: Replace the UBPT agreement with a new offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the existing agreement. RequestedTerm newUsageBasedPricingTerm = RequestedTerm.builder().id(NEW_USAGE_BASED_PRICING_TERM_ID).build(); RequestedTerm newValidityTerm = RequestedTerm.builder().id(NEW_VALIDITY_TERM_ID).build(); RequestedTerm newLegalTerm = RequestedTerm.builder().id(NEW_LEGAL_TERM_ID).build(); CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(newUsageBasedPricingTerm, newValidityTerm, newLegalTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(acceptAgreementRequestResponse.agreementId()) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); final String agreementIdWithTheNewOffer = aarResponse.agreementId(); System.out.println("UBPT agreement replaced. New AgreementId: " + agreementIdWithTheNewOffer); // --- Step 3: Cancel the new agreement --- CancelAgreementRequest cancelAgreementRequest = CancelAgreementRequest.builder() .agreementId(agreementIdWithTheNewOffer) .build(); marketplaceAgreementClient.cancelAgreement(cancelAgreementRequest); System.out.println("The new agreement has been cancelled. AgreementId: " + agreementIdWithTheNewOffer); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to replace an AMI usage-based pricing term while keeping the existing ConfigurableUpfrontPricingTerm.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.GetAgreementEntitlementsResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import utils.AgreementApiUtils; /** * Demonstrates how to replace an AMI agreement with usageBasedPricingTerm with a new offer while * the agreement with ConfigurableUpfrontPricingTerm (CUPT) is still active, using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: An AMI product with USAGE pricing requires two agreements: * <ol> * <li>An agreement with <b>usageBasedPricingTerm</b> — accepted first to establish the base agreement.</li> * <li>An agreement with <b>configurableUpfrontPricingTerm (CUPT)</b> — accepted after the usageBasedPricingTerm agreement entitlements are active.</li> * </ol> * <p> This sample shows how to replace only the agreement with usageBasedPricingTerm with a * new offer without touching the existing agreement with configurableUpfrontPricingTerm (CUPT). * * <p>Flow: * <ol> * <li>Create and accept the initial agreement request with usageBasedPricingTerm.</li> * <li>Create and accept the agreement request with configurableUpfrontPricingTerm (CUPT) (after usageBasedPricingTerm agreement entitlements are active).</li> * <li>Replace the agreement with usageBasedPricingTerm with a new offer using Intent.REPLACE.</li> * </ol> * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the initial offer.</li> * <li>{@code NEW_AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the new offer to replace to.</li> * <li>Term IDs (starting with {@code term-}) — found in each offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement (e.g., {@code P365D}).</li> * <li>{@code DIMENSION_1_KEY} — dimension key defined in the CUPT term.</li> * </ul> */ public class ReplaceAmiUsageBasedPricingTermButNotCupt { // The agreementProposalId from the initial offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in the initial offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P365D" for 365 days). private static final String SELECTOR_VALUE = "<your-selector-value>"; // Dimension key defined in the CUPT term. private static final String DIMENSION_1_KEY = "<your-dimension-key>"; // Quantity for the dimension. private static final int DIMENSION_1_VALUE = 1; // Term ID for the UsageBasedPricingTerm in the initial offer. private static final String USAGE_TERM_ID = "<your-usage-term-id>"; // Term ID for the LegalTerm in the initial offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the initial offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; // The agreementProposalId from the new offer to replace to. private static final String NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the new offer. private static final String NEW_USAGE_TERM_ID = "<your-new-usage-term-id>"; // Term ID for the LegalTerm in the new offer. private static final String NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. private static final String NEW_VALIDITY_TERM_ID = "<your-new-validity-term-id>"; public static void main(String[] args) { replaceAmiUsageWhenCuptExists(); } /** * Full end-to-end flow: * 1. Create and accept an agreement request with usageBasedPricingTerm, then wait for entitlements. * 2. Create and accept an agreement request with CUPT, then wait for entitlements. * 3. Replace the agreement with usageBasedPricingTerm with a new offer (agreement with CUPT is unaffected). */ private static void replaceAmiUsageWhenCuptExists() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm usageTerm = RequestedTerm.builder().id(USAGE_TERM_ID).build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); // --- Step 1: Agreement with UBPT --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(usageTerm, legalTerm, validityTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); final String usageAgreementId = acceptAgreementRequestResponse.agreementId(); System.out.println("Agreement request with UBPT accepted. AgreementId: " + usageAgreementId); // Wait for UBPT agreement entitlements to become active before creating the agreement with CUPT. System.out.println("Waiting for UBPT agreement entitlements to become active..."); GetAgreementEntitlementsResponse entitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, usageAgreementId); System.out.println("UBPT agreement entitlements are now active."); AgreementApiUtils.formatOutput(entitlementsResponse); // --- Step 2: Agreement with configurableUpfrontPricingTerm (CUPT) --- RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build()) .build())) .build(); CreateAgreementRequestRequest carRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, legalTerm, validityTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse carResponse = marketplaceAgreementClient.createAgreementRequest(carRequest); System.out.println("Agreement request with CUPT created. AgreementRequestId: " + carResponse.agreementRequestId()); AcceptAgreementRequestRequest aarRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarResponse = marketplaceAgreementClient.acceptAgreementRequest(aarRequest); final String cuptAgreementId = aarResponse.agreementId(); System.out.println("Agreement request with CUPT accepted. AgreementId: " + cuptAgreementId); // Wait for CUPT agreement entitlements to become active before replacing usage. System.out.println("Waiting for CUPT agreement entitlements to become active..."); GetAgreementEntitlementsResponse cuptEntitlementsResponse = AgreementApiUtils.pollUntilEntitlementsAvailable( marketplaceAgreementClient, cuptAgreementId); System.out.println("CUPT agreement entitlements are now active."); AgreementApiUtils.formatOutput(cuptEntitlementsResponse); // --- Step 3: Replace Agreement with usageBasedPricingTerm with a new offer --- RequestedTerm newUsageTerm = RequestedTerm.builder().id(NEW_USAGE_TERM_ID).build(); RequestedTerm newLegalTerm = RequestedTerm.builder().id(NEW_LEGAL_TERM_ID).build(); RequestedTerm newValidityTerm = RequestedTerm.builder().id(NEW_VALIDITY_TERM_ID).build(); // Use Intent.REPLACE and sourceAgreementIdentifier pointing to the usageBasedPricingTerm agreement only. // The agreement with configurableUpfrontPricingTerm (CUPT) is NOT affected by this replacement. CreateAgreementRequestRequest carReplaceRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.REPLACE) .requestedTerms(newUsageTerm, newLegalTerm, newValidityTerm) .agreementProposalIdentifier(NEW_AGREEMENT_PROPOSAL_IDENTIFIER) .sourceAgreementIdentifier(usageAgreementId) .build(); CreateAgreementRequestResponse carReplaceResponse = marketplaceAgreementClient.createAgreementRequest(carReplaceRequest); System.out.println("Replace agreement request created. AgreementRequestId: " + carReplaceResponse.agreementRequestId()); AcceptAgreementRequestRequest aarReplaceRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(carReplaceResponse.agreementRequestId()) .build(); AcceptAgreementRequestResponse aarReplaceResponse = marketplaceAgreementClient.acceptAgreementRequest(aarReplaceRequest); System.out.println("Agreement with UBPT replaced. New AgreementId: " + aarReplaceResponse.agreementId()); } }-
For API details, see CreateAgreementRequest in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to search for agreements by end date.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; public class SearchAgreementsByEndDate { static String beforeOrAfterEndtimeFilterName = BeforeOrAfterEndTimeFilterName.BeforeEndTime.name(); static String cutoffDate = "2050-11-18T00:00:00Z"; static String partyTypeFilterValue = PARTY_TYPE_FILTER_VALUE_PROPOSER; public static void main(String[] args) { List<AgreementViewSummary> agreementSummaryList = getAgreements(); ReferenceCodesUtils.formatOutput(agreementSummaryList); } public static List<AgreementViewSummary> getAgreements() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. // Change to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. Filter partyTypeFilter = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementTypeFilter = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); Filter customizeFilter = Filter.builder().name(beforeOrAfterEndtimeFilterName).values(cutoffDate).build(); List<Filter> filters = new ArrayList<Filter>(); filters.addAll(Arrays.asList(partyTypeFilter, agreementTypeFilter, customizeFilter)); // search agreement with filters SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .build(); SearchAgreementsResponse searchAgreementResponse= marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); agreementSummaryList.addAll(searchAgreementResponse.agreementViewSummaries()); while (searchAgreementResponse.nextToken() != null && searchAgreementResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .nextToken(searchAgreementResponse.nextToken()) .build(); searchAgreementResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementResponse.agreementViewSummaries()); } return agreementSummaryList; } }-
For API details, see SearchAgreements in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to search for agreements with one custom filter.
- 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. package com.example.awsmarketplace.agreementapi.seller; 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.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import com.example.awsmarketplace.utils.ReferenceCodesUtils; /** * All filter combinations we support for Proposer and Acceptor: * https://docs.aws.amazon.com/marketplace/latest/APIReference/API_marketplace-agreements_SearchAgreements.html */ public class SearchAgreementsByOneFilter { private static final String FILTER_NAME = "ResourceType"; private static final String FILTER_VALUE = "SaaSProduct"; /* * search agreements by one customize filter */ public static void main(String[] args) { List<AgreementViewSummary> agreementSummaryList = getAgreements(); ReferenceCodesUtils.formatOutput(agreementSummaryList); } public static List<AgreementViewSummary> getAgreements() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. // Change to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. Filter partyTypeFilter = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementTypeFilter = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); Filter customizeFilter = Filter.builder().name(FILTER_NAME).values(FILTER_VALUE).build(); List<Filter> filters = new ArrayList<Filter>(); filters.addAll(Arrays.asList(partyTypeFilter, agreementTypeFilter, customizeFilter)); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .build(); SearchAgreementsResponse searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); while (searchAgreementsResponse.nextToken() != null && searchAgreementsResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .nextToken(searchAgreementsResponse.nextToken()) .build(); searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); } return agreementSummaryList; } }-
For API details, see SearchAgreements in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to search for agreements with two custom filters.
- 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. package com.example.awsmarketplace.agreementapi.seller; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.SdkHttpClient; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient; import software.amazon.awssdk.services.marketplaceagreement.model.AgreementViewSummary; import software.amazon.awssdk.services.marketplaceagreement.model.Filter; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsRequest; import software.amazon.awssdk.services.marketplaceagreement.model.SearchAgreementsResponse; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*; import com.example.awsmarketplace.utils.ReferenceCodesUtils; /** * All filter combinations we support for Proposer and Acceptor: * https://docs.aws.amazon.com/marketplace/latest/APIReference/API_marketplace-agreements_SearchAgreements.html */ public class SearchAgreementsByTwoFilters { public static final String FILTER_1_NAME = "ResourceType"; public static final String FILTER_1_VALUE = "SaaSProduct"; public static final String FILTER_2_NAME = "Status"; public static final String FILTER_2_VALUE = "ACTIVE"; /* * search agreements by two customize filter */ public static void main(String[] args) { List<AgreementViewSummary> agreementSummaryList = getAgreements(); ReferenceCodesUtils.formatOutput(agreementSummaryList); } public static List<AgreementViewSummary> getAgreements() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); // Set PartyType filter to PARTY_TYPE_FILTER_VALUE_PROPOSER to return agreements where you are the proposer. // Change to PARTY_TYPE_FILTER_VALUE_ACCEPTOR to return agreements where you are the acceptor. Filter partyTypeFilter = Filter.builder().name(PARTY_TYPE_FILTER_NAME) .values(PARTY_TYPE_FILTER_VALUE_PROPOSER).build(); Filter agreementTypeFilter = Filter.builder().name(AGREEMENT_TYPE_FILTER_NAME) .values(AGREEMENT_TYPE_FILTER_VALUE_PURCHASEAGREEMENT).build(); Filter customizeFilter1 = Filter.builder().name(FILTER_1_NAME).values(FILTER_1_VALUE).build(); Filter customizeFilter2 = Filter.builder().name(FILTER_2_NAME).values(FILTER_2_VALUE).build(); List<Filter> filters = new ArrayList<Filter>(); filters.addAll(Arrays.asList(partyTypeFilter, agreementTypeFilter, customizeFilter1, customizeFilter2)); SearchAgreementsRequest searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .build(); SearchAgreementsResponse searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); List<AgreementViewSummary> agreementSummaryList = new ArrayList<AgreementViewSummary>(); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); while (searchAgreementsResponse.nextToken() != null && searchAgreementsResponse.nextToken().length() > 0) { searchAgreementsRequest = SearchAgreementsRequest.builder() .catalog(AWS_MP_CATALOG) .filters(filters) .nextToken(searchAgreementsResponse.nextToken()) .build(); searchAgreementsResponse = marketplaceAgreementClient.searchAgreements(searchAgreementsRequest); agreementSummaryList.addAll(searchAgreementsResponse.agreementViewSummaries()); } return agreementSummaryList; } }-
For API details, see SearchAgreements in AWS SDK for Java 2.x API Reference.
-
The following code example shows how to update purchase orders after the agreement has been accepted.
- 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. package com.example.awsmarketplace.agreementapi.buyer; 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.AcceptAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.AcceptAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Charge; import software.amazon.awssdk.services.marketplaceagreement.model.ConfigurableUpfrontPricingTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestRequest; import software.amazon.awssdk.services.marketplaceagreement.model.CreateAgreementRequestResponse; import software.amazon.awssdk.services.marketplaceagreement.model.Dimension; import software.amazon.awssdk.services.marketplaceagreement.model.Intent; import software.amazon.awssdk.services.marketplaceagreement.model.ListAgreementChargesRequest; import software.amazon.awssdk.services.marketplaceagreement.model.ListAgreementChargesResponse; import software.amazon.awssdk.services.marketplaceagreement.model.PurchaseOrder; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTerm; import software.amazon.awssdk.services.marketplaceagreement.model.RequestedTermConfiguration; import software.amazon.awssdk.services.marketplaceagreement.model.UpdatePurchaseOrdersRequest; import utils.AgreementApiUtils; /** * Demonstrates how to associate a purchase order reference with a SaaS agreement with CONTRACT pricing model * using the AWS Marketplace Agreement Service APIs. * * <p>Scenario: A buyer creates a SaaS agreement request with CONTRACT pricing model and provides a purchase order * reference in AcceptAgreementRequest. After acceptance, the buyer lists the resulting * charges via ListAgreementCharges and associates the purchase order reference with a * specific charge via UpdatePurchaseOrders. * * <p>Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * <ul> * <li>{@code AGREEMENT_PROPOSAL_IDENTIFIER} — the agreementProposalId from the offer.</li> * <li>Term IDs (starting with {@code term-}) — found in the offer's term list.</li> * <li>{@code SELECTOR_VALUE} — duration for the agreement.</li> * <li>{@code DIMENSION_1_KEY} — dimension key defined in the offer.</li> * <li>{@code PURCHASE_ORDER_REFERENCE} — your internal purchase order number (e.g., {@code po-123456}).</li> * </ul> */ public class UpdatePurchaseOrdersAfterAgreementAcceptance { // Your internal purchase order reference number (e.g., "po-123456"). private static final String PURCHASE_ORDER_REFERENCE = "po-123456"; // The agreementProposalId from the offer. private static final String AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. private static final String CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P366D" for 366 days). private static final String SELECTOR_VALUE = "<your-selector-value>"; // Dimension key and quantity defined in your offer. private static final String DIMENSION_1_KEY = "<your-dimension-key>"; private static final int DIMENSION_1_VALUE = 1; // Term ID for the LegalTerm in your offer. private static final String LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in your offer. private static final String VALIDITY_TERM_ID = "<your-validity-term-id>"; public static void main(String[] args) { listAgreementChargesAndUpdatePurchaseOrders(); } /** * Full end-to-end flow: * 1. Create a SaaS agreement with CONTRACT pricing model with a purchase order reference. * 2. List charges to retrieve charge IDs and revisions. * 3. Associate the purchase order reference with a specific charge via UpdatePurchaseOrders. * 4. List charges again to confirm the update. */ private static void listAgreementChargesAndUpdatePurchaseOrders() { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); RequestedTerm configurableUpfrontPricingTerm = RequestedTerm.builder() .id(CONFIGURABLE_UPFRONT_PRICING_TERM_ID) .configuration(RequestedTermConfiguration.fromConfigurableUpfrontPricingTermConfiguration( ConfigurableUpfrontPricingTermConfiguration.builder() .selectorValue(SELECTOR_VALUE) .dimensions(Dimension.builder() .dimensionKey(DIMENSION_1_KEY) .dimensionValue(DIMENSION_1_VALUE) .build()) .build())) .build(); RequestedTerm legalTerm = RequestedTerm.builder().id(LEGAL_TERM_ID).build(); RequestedTerm validityTerm = RequestedTerm.builder().id(VALIDITY_TERM_ID).build(); // --- Create Agreement --- CreateAgreementRequestRequest createAgreementRequestRequest = CreateAgreementRequestRequest.builder() .clientToken(AgreementApiUtils.generateClientToken()) .intent(Intent.NEW) .requestedTerms(configurableUpfrontPricingTerm, legalTerm, validityTerm) .agreementProposalIdentifier(AGREEMENT_PROPOSAL_IDENTIFIER) .build(); CreateAgreementRequestResponse createAgreementRequestResponse = marketplaceAgreementClient.createAgreementRequest(createAgreementRequestRequest); System.out.println("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId()); // --- Accept Agreement Request with Purchase Order --- // The chargeId is available from the CAR response's chargeSummary.expectedCharges. String chargeId = createAgreementRequestResponse.chargeSummary().expectedCharges().get(0).id(); PurchaseOrder purchaseOrderAtAcceptance = PurchaseOrder.builder() .chargeId(chargeId) .purchaseOrderReference(PURCHASE_ORDER_REFERENCE) .build(); AcceptAgreementRequestRequest acceptAgreementRequestRequest = AcceptAgreementRequestRequest.builder() .agreementRequestId(createAgreementRequestResponse.agreementRequestId()) .purchaseOrders(purchaseOrderAtAcceptance) .build(); AcceptAgreementRequestResponse acceptAgreementRequestResponse = marketplaceAgreementClient.acceptAgreementRequest(acceptAgreementRequestRequest); final String agreementId = acceptAgreementRequestResponse.agreementId(); System.out.println("Agreement request accepted with purchase order reference '" + PURCHASE_ORDER_REFERENCE + "'. AgreementId: " + agreementId); // --- List Agreement Charges --- ListAgreementChargesRequest listAgreementChargesRequest = ListAgreementChargesRequest.builder() .agreementId(agreementId) .build(); ListAgreementChargesResponse listAgreementChargesResponse = marketplaceAgreementClient.listAgreementCharges(listAgreementChargesRequest); System.out.println("All charges for agreement " + agreementId + ":"); AgreementApiUtils.formatOutput(listAgreementChargesResponse); // --- Update Purchase Order --- Charge firstCharge = listAgreementChargesResponse.items().get(0); PurchaseOrder purchaseOrder = PurchaseOrder.builder() .agreementId(agreementId) .purchaseOrderReference(PURCHASE_ORDER_REFERENCE) .chargeRevision(firstCharge.revision()) .chargeId(firstCharge.id()) .build(); UpdatePurchaseOrdersRequest updatePurchaseOrdersRequest = UpdatePurchaseOrdersRequest.builder() .purchaseOrders(purchaseOrder) .build(); marketplaceAgreementClient.updatePurchaseOrders(updatePurchaseOrdersRequest); System.out.println("Purchase order reference '" + PURCHASE_ORDER_REFERENCE + "' updated for ChargeId: " + firstCharge.id()); // --- Verify Update --- ListAgreementChargesRequest lacRequest = ListAgreementChargesRequest.builder() .agreementId(agreementId) .build(); ListAgreementChargesResponse lacResponse = marketplaceAgreementClient.listAgreementCharges(lacRequest); System.out.println("Verified updated charge:"); AgreementApiUtils.formatOutput(lacResponse.items().get(0)); } }-
For API details, see UpdatePurchaseOrders in AWS SDK for Java 2.x API Reference.
-