View a markdown version of this page

Replace a SaaS contract agreement with an agreement-based offer using an AWS SDK - AWS SDK Code Examples

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

Replace a SaaS contract agreement with an agreement-based offer using an AWS SDK

The following code examples show how to replace a SaaS contract agreement with a new agreement-based offer.

Java
SDK for Java 2.x
Note

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

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()); } }
JavaScript
SDK for JavaScript (v3)
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.

const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken } = require("./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. * * 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. * * Note: Unlike other Replace samples, this example starts from an already-active * 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. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - EXISTING_AGREEMENT_ID — the agreement ID of the active agreement to replace (starts with "agmt-"). * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new ABO offer. * - Term IDs (starting with "term-") — found in the new offer's term list. */ // The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). const EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>"; // The agreementProposalId from the new Agreement-Based Offer. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the LegalTerm in the new offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the FixedUpfrontPricingTerm in the new offer. const FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the new offer. const PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; /** * 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. */ async function replaceExistingAgreement() { const client = new MarketplaceAgreementClient(); const legalTerm = { id: LEGAL_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; const fixedUpfrontPricingTerm = { id: FIXED_UPFRONT_PRICING_TERM_ID }; const paymentScheduleTerm = { id: PAYMENT_SCHEDULE_TERM_ID }; // Replace the agreement with the new offer const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [fixedUpfrontPricingTerm, paymentScheduleTerm, legalTerm, validityTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: EXISTING_AGREEMENT_ID, }) ); console.log("Replace agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement replaced with ABO. New AgreementId: " + acceptAgreementRequestResponse.agreementId); } replaceExistingAgreement();
Python
SDK for Python (Boto3)
Note

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

""" 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. 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. Note: Unlike other Replace samples, this example starts from an already-active 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. Before running this sample, replace the placeholder constants below with values from your AWS Marketplace offers: - EXISTING_AGREEMENT_ID — the agreement ID of the active agreement to replace (starts with agmt-). - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new ABO offer. - Term IDs (starting with term-) — found in the new offer's term list. """ import boto3 from utils.agreement_api_utils import generate_client_token class ReplaceSaaSContractWithAgreementBasedOffer: # The agreement ID of the active SaaS agreement with CONTRACT pricing model to replace (starts with "agmt-"). EXISTING_AGREEMENT_ID = "<your-existing-agreement-id>" # The agreementProposalId from the new Agreement-Based Offer. NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>" # Term ID for the LegalTerm in the new offer. LEGAL_TERM_ID = "<your-legal-term-id>" # Term ID for the ValidityTerm in the new offer. VALIDITY_TERM_ID = "<your-validity-term-id>" # Term ID for the FixedUpfrontPricingTerm in the new offer. FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>" # Term ID for the PaymentScheduleTerm in the new offer. PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>" @staticmethod def replace_existing_agreement(): """ Replace 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. """ client = boto3.client("marketplace-agreement") cls = ReplaceSaaSContractWithAgreementBasedOffer legal_term = {"id": cls.LEGAL_TERM_ID} validity_term = {"id": cls.VALIDITY_TERM_ID} fixed_upfront_pricing_term = {"id": cls.FIXED_UPFRONT_PRICING_TERM_ID} payment_schedule_term = {"id": cls.PAYMENT_SCHEDULE_TERM_ID} # Replace the agreement with the new offer create_response = client.create_agreement_request( clientToken=generate_client_token(), intent="REPLACE", requestedTerms=[fixed_upfront_pricing_term, payment_schedule_term, legal_term, validity_term], agreementProposalIdentifier=cls.NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier=cls.EXISTING_AGREEMENT_ID, ) agreement_request_id = create_response["agreementRequestId"] print("Replace agreement request created. AgreementRequestId: " + agreement_request_id) accept_response = client.accept_agreement_request( agreementRequestId=agreement_request_id ) print("Agreement replaced with ABO. New AgreementId: " + accept_response["agreementId"]) if __name__ == "__main__": ReplaceSaaSContractWithAgreementBasedOffer.replace_existing_agreement()