Há mais exemplos de AWS SDK disponíveis no repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
AWS Marketplace Exemplos de API de contrato usando SDK para JavaScript (v3)
Os exemplos de código a seguir mostram como realizar ações e implementar cenários comuns usando a AWS SDK para JavaScript (v3) com a API AWS Marketplace Agreement.
Cada exemplo inclui um link para o código-fonte completo, em que você pode encontrar instruções sobre como configurar e executar o código.
Tópicos
Contratos
O exemplo de código a seguir mostra como aceitar uma solicitação de cancelamento de contrato iniciada pelo vendedor.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, AcceptAgreementCancellationRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; async function acceptAgreementCancellationRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new AcceptAgreementCancellationRequestCommand({ agreementId: AGREEMENT_ID, agreementCancellationRequestId: AGREEMENT_CANCELLATION_REQUEST_ID, }) ); console.log("Agreement ID: " + response.agreementId); console.log("Cancellation Request ID: " + response.agreementCancellationRequestId); console.log("Status: " + response.status); console.log("Description: " + response.description); console.log("Reason Code: " + response.reasonCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } acceptAgreementCancellationRequest();-
Para obter detalhes da API, consulte AcceptAgreementCancellationRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como aceitar uma solicitação de pagamento do contrato iniciada pelo vendedor.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, AcceptAgreementPaymentRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; const PURCHASE_ORDER_REFERENCE = "<PURCHASE ORDER REFERENCE HERE>"; async function acceptAgreementPaymentRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new AcceptAgreementPaymentRequestCommand({ agreementId: AGREEMENT_ID, paymentRequestId: PAYMENT_REQUEST_ID, purchaseOrderReference: PURCHASE_ORDER_REFERENCE, }) ); console.log("Payment Request ID: " + response.paymentRequestId); console.log("Agreement ID: " + response.agreementId); console.log("Status: " + response.status); console.log("Name: " + response.name); console.log("Charge Amount: " + response.chargeAmount); console.log("Currency Code: " + response.currencyCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } acceptAgreementPaymentRequest();-
Para obter detalhes da API, consulte AcceptAgreementPaymentRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como alterar um contrato de SaaS para adicionar ou atualizar seu prazo de renovação.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput, pollUntilEntitlementsAvailable } = require("./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. * * 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. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. * - SELECTOR_VALUE — duration for the agreement (e.g., "P1M" for 1 month). * - DIMENSION_1_KEY — the dimension key defined in the offer. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. const 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). const SELECTOR_VALUE = "<your-selector-value>"; // The dimension key defined in your offer. const DIMENSION_1_KEY = "<your-dimension-key>"; // Quantity for the dimension. const DIMENSION_1_VALUE = 1; // Term ID for the RenewalTerm in your offer. const RENEWAL_TERM_ID = "<your-renewal-term-id>"; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the SupportTerm in your offer. const SUPPORT_TERM_ID = "<your-support-term-id>"; /** * 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. */ async function amendSaaSContractAgreementRenewalTerm() { const client = new MarketplaceAgreementClient(); const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, ], }, }, }; // Initial agreement: auto-renewal disabled. const renewalTerm = { id: RENEWAL_TERM_ID, configuration: { renewalTermConfiguration: { enableAutoRenew: false, }, }, }; const legalTerm = { id: LEGAL_TERM_ID }; const supportTerm = { id: SUPPORT_TERM_ID }; // --- Create and accept the initial SaaS agreement request with CONTRACT pricing model --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, renewalTerm, legalTerm, supportTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); // Wait for entitlements to become active before amending. console.log("Waiting for entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, acceptAgreementRequestResponse.agreementId); console.log("Entitlements are now active."); formatOutput(entitlementsResponse); // --- Amend: enable auto-renewal --- const renewalTermAmended = { id: RENEWAL_TERM_ID, configuration: { renewalTermConfiguration: { enableAutoRenew: true, }, }, }; // Use Intent.AMEND and sourceAgreementIdentifier to target the existing agreement. const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "AMEND", requestedTerms: [configurableUpfrontPricingTerm, renewalTermAmended, legalTerm, supportTerm], sourceAgreementIdentifier: acceptAgreementRequestResponse.agreementId, }) ); console.log("Amend agreement request created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); console.log("Amendment accepted. Auto-renewal enabled. New AgreementId: " + aarResponse.agreementId); } amendSaaSContractAgreementRenewalTerm();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como alterar um contrato de AMI ConfigurableUpfrontPricingTerm atualizando a quantidade da dimensão para o modelo de preços de uso.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput, pollUntilEntitlementsAvailable } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to create an AMI agreement with ConfigurableUpfrontPricingTerm and then amend the dimension quantity * using the AWS Marketplace Agreement Service APIs. * * Scenario: An AMI product with USAGE pricing requires two agreements: * 1. An agreement with usageBasedPricingTerm (UBPT) — accepted first to establish the base agreement. * 2. An agreement with configurableUpfrontPricingTerm (CUPT) — accepted after the UBPT agreement entitlements are active. * * Once both agreement entitlements are available, this sample shows how to amend the agreement * with configurableUpfrontPricingTerm (CUPT) to increase the dimension quantity. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. * - SELECTOR_VALUE — duration for the agreement (e.g., "P365D" for one year). * - DIMENSION_1_KEY — the dimension key defined in the offer (e.g., instance type). * - DIMENSION_1_VALUE — initial quantity; NEW_DIMENSION_1_VALUE — amended quantity. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. const CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P365D" for 365 days). const SELECTOR_VALUE = "<your-selector-value>"; // The dimension key defined in your offer (e.g., an EC2 instance type like "c6gn.medium"). const DIMENSION_1_KEY = "<your-dimension-key>"; // Initial quantity for the dimension. const DIMENSION_1_VALUE = 1; // Term ID for the UsageBasedPricingTerm in your offer. const USAGE_TERM_ID = "<your-usage-term-id>"; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in your offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // New quantity to use when amending the dimension of CUPT. const NEW_DIMENSION_1_VALUE = 5; /** * 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. */ async function amendAmiCUPTAgreement() { const client = new MarketplaceAgreementClient(); const usageTerm = { id: USAGE_TERM_ID }; const legalTerm = { id: LEGAL_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; // --- Agreement with UBPT --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [usageTerm, legalTerm, validityTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with UBPT accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); // Wait for entitlements to become active before creating the agreement with CUPT. console.log("Waiting for UBPT agreement entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, acceptAgreementRequestResponse.agreementId); console.log("UBPT agreement entitlements are now active."); formatOutput(entitlementsResponse); // --- Agreement with configurableUpfrontPricingTerm (CUPT) --- const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, ], }, }, }; const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, legalTerm, validityTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with CUPT created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); const cuptAgreementId = aarResponse.agreementId; console.log("Agreement request with CUPT accepted. AgreementId: " + cuptAgreementId); // Wait for entitlements to become active before amending. console.log("Waiting for CUPT agreement entitlements to become active..."); const cuptEntitlementsResponse = await pollUntilEntitlementsAvailable(client, cuptAgreementId); console.log("CUPT agreement entitlements are now active."); formatOutput(cuptEntitlementsResponse); // --- Amend Agreement with CUPT --- // Increase the dimension quantity using Intent.AMEND and sourceAgreementIdentifier. const newConfig = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: NEW_DIMENSION_1_VALUE }, // Increase quantity for this dimension key ], }, }, }; const carAmendResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "AMEND", requestedTerms: [newConfig, legalTerm, validityTerm], sourceAgreementIdentifier: cuptAgreementId, }) ); console.log("Amendment of CUPT agreement request created. AgreementRequestId: " + carAmendResponse.agreementRequestId); const aarAmendResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carAmendResponse.agreementRequestId, }) ); console.log("Amendment accepted. New AgreementId: " + aarAmendResponse.agreementId); } amendAmiCUPTAgreement();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como criar um novo contrato de teste gratuito da AMI.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to create an AMI Free Trial agreement * using the AWS Marketplace Agreement Service APIs. * * Scenario: A buyer subscribes to an AMI product that offers a free trial period. * The free trial includes a FreeTrialPricingTerm alongside a UsageBasedPricingTerm. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in your offer. const FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the UsageBasedPricingTerm in your offer (applies after the trial ends). const USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the SupportTerm in your offer. const SUPPORT_TERM_ID = "<your-support-term-id>"; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; /** * 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. */ async function createAndAcceptAmiFreeTrialAgreementRequest() { const client = new MarketplaceAgreementClient(); const freeTrialPricingTerm = { id: FREE_TRIAL_PRICING_TERM_ID }; const usageBasedPricingTerm = { id: USAGE_BASED_PRICING_TERM_ID }; const supportTerm = { id: SUPPORT_TERM_ID }; const legalTerm = { id: LEGAL_TERM_ID }; const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [freeTrialPricingTerm, usageBasedPricingTerm, supportTerm, legalTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); } createAndAcceptAmiFreeTrialAgreementRequest();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como criar um novo contrato de SaaS com pagamento adiantado.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken } = require("./utils/AgreementApiUtils"); /** * Demonstrates how to create a SaaS agreement with CONTRACT pricing model with upfront payment * using the AWS Marketplace Agreement Service APIs. * * 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. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. * - SELECTOR_VALUE — duration for the agreement (e.g., "P12M" for 12 months). * - DIMENSION_1_KEY, DIMENSION_2_KEY — dimension keys defined in the offer. * - DIMENSION_1_VALUE, DIMENSION_2_VALUE — quantities for each dimension. */ // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. const CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P12M" for 12 months). const SELECTOR_VALUE = "<your-selector-value>"; // First dimension key and quantity defined in your offer. const DIMENSION_1_KEY = "<your-dimension-1-key>"; const DIMENSION_1_VALUE = 10; // Second dimension key and quantity defined in your offer. const DIMENSION_2_KEY = "<your-dimension-2-key>"; const DIMENSION_2_VALUE = 20; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Tax estimation setting: "ENABLED" to include estimated taxes in the agreement. const TAX_ESTIMATION = "ENABLED"; /** * Creates a SaaS agreement with CONTRACT pricing model with configurable upfront pricing * for multiple dimensions and tax estimation. */ async function createSaaSContractAgreement() { const client = new MarketplaceAgreementClient(); const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, { dimensionKey: DIMENSION_2_KEY, dimensionValue: DIMENSION_2_VALUE }, ], }, }, }; const legalTerm = { id: LEGAL_TERM_ID }; const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, legalTerm], taxConfiguration: { taxEstimation: TAX_ESTIMATION }, agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("SaaS agreement request with CONTRACT pricing model accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); } createSaaSContractAgreement();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como obter detalhes de uma solicitação de cancelamento de contrato específica.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, GetAgreementCancellationRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; async function getAgreementCancellationRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new GetAgreementCancellationRequestCommand({ agreementId: AGREEMENT_ID, agreementCancellationRequestId: AGREEMENT_CANCELLATION_REQUEST_ID, }) ); console.log("Agreement ID: " + response.agreementId); console.log("Cancellation Request ID: " + response.agreementCancellationRequestId); console.log("Status: " + response.status); console.log("Status Message: " + response.statusMessage); console.log("Reason Code: " + response.reasonCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } getAgreementCancellationRequest();-
Para obter detalhes da API, consulte GetAgreementCancellationRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como obter detalhes de uma solicitação de pagamento de um contrato específico.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, GetAgreementPaymentRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; async function getAgreementPaymentRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new GetAgreementPaymentRequestCommand({ agreementId: AGREEMENT_ID, paymentRequestId: PAYMENT_REQUEST_ID, }) ); console.log("Payment Request ID: " + response.paymentRequestId); console.log("Agreement ID: " + response.agreementId); console.log("Status: " + response.status); console.log("Status Message: " + response.statusMessage); console.log("Name: " + response.name); console.log("Charge ID: " + response.chargeId); console.log("Charge Amount: " + response.chargeAmount); console.log("Currency Code: " + response.currencyCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } getAgreementPaymentRequest();-
Para obter detalhes da API, consulte GetAgreementPaymentRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como listar as solicitações de cancelamento de contratos dos quais participo como aceitantes.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, ListAgreementCancellationRequestsCommand, } = require("@aws-sdk/client-marketplace-agreement"); const PARTY_TYPE = "Proposer"; async function listAgreementCancellationRequests() { const client = new MarketplaceAgreementClient(); let nextToken = null; do { const response = await client.send( new ListAgreementCancellationRequestsCommand({ partyType: PARTY_TYPE, nextToken: nextToken, }) ); for (const summary of response.items) { console.log("Cancellation Request ID: " + summary.agreementCancellationRequestId); console.log("Agreement ID: " + summary.agreementId); console.log("Status: " + summary.status); console.log("Reason Code: " + summary.reasonCode); console.log("Agreement Type: " + summary.agreementType); console.log("Catalog: " + summary.catalog); console.log("Created At: " + summary.createdAt); console.log("Updated At: " + summary.updatedAt); console.log("---"); } nextToken = response.nextToken; } while (nextToken != null); } listAgreementCancellationRequests();-
Para obter detalhes da API, consulte ListAgreementCancellationRequestsa Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como listar as solicitações de pagamento de contratos dos quais participo como aceitantes.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, ListAgreementPaymentRequestsCommand, } = require("@aws-sdk/client-marketplace-agreement"); const PARTY_TYPE = "Proposer"; async function listAgreementPaymentRequests() { const client = new MarketplaceAgreementClient(); let nextToken = null; do { const response = await client.send( new ListAgreementPaymentRequestsCommand({ partyType: PARTY_TYPE, nextToken: nextToken, }) ); for (const summary of response.items) { console.log("Payment Request ID: " + summary.paymentRequestId); console.log("Agreement ID: " + summary.agreementId); console.log("Status: " + summary.status); console.log("Name: " + summary.name); console.log("Charge ID: " + summary.chargeId); console.log("Charge Amount: " + summary.chargeAmount); console.log("Currency Code: " + summary.currencyCode); console.log("Created At: " + summary.createdAt); console.log("Updated At: " + summary.updatedAt); console.log("---"); } nextToken = response.nextToken; } while (nextToken != null); } listAgreementPaymentRequests();-
Para obter detalhes da API, consulte ListAgreementPaymentRequestsa Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como rejeitar uma solicitação de cancelamento de contrato iniciada pelo vendedor.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, RejectAgreementCancellationRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const AGREEMENT_CANCELLATION_REQUEST_ID = "<AGREEMENT CANCELLATION REQUEST ID HERE>"; const REJECTION_REASON = "<REJECTION REASON HERE>"; async function rejectAgreementCancellationRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new RejectAgreementCancellationRequestCommand({ agreementId: AGREEMENT_ID, agreementCancellationRequestId: AGREEMENT_CANCELLATION_REQUEST_ID, rejectionReason: REJECTION_REASON, }) ); console.log("Agreement ID: " + response.agreementId); console.log("Cancellation Request ID: " + response.agreementCancellationRequestId); console.log("Status: " + response.status); console.log("Status Message: " + response.statusMessage); console.log("Reason Code: " + response.reasonCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } rejectAgreementCancellationRequest();-
Para obter detalhes da API, consulte RejectAgreementCancellationRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como rejeitar uma solicitação de pagamento do contrato iniciada pelo vendedor.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, RejectAgreementPaymentRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const AGREEMENT_ID = "<AGREEMENT ID HERE>"; const PAYMENT_REQUEST_ID = "<PAYMENT REQUEST ID HERE>"; const REJECTION_REASON = "<REJECTION REASON HERE>"; async function rejectAgreementPaymentRequest() { const client = new MarketplaceAgreementClient(); const response = await client.send( new RejectAgreementPaymentRequestCommand({ agreementId: AGREEMENT_ID, paymentRequestId: PAYMENT_REQUEST_ID, rejectionReason: REJECTION_REASON, }) ); console.log("Payment Request ID: " + response.paymentRequestId); console.log("Agreement ID: " + response.agreementId); console.log("Status: " + response.status); console.log("Status Message: " + response.statusMessage); console.log("Name: " + response.name); console.log("Charge Amount: " + response.chargeAmount); console.log("Currency Code: " + response.currencyCode); console.log("Created At: " + response.createdAt); console.log("Updated At: " + response.updatedAt); } rejectAgreementPaymentRequest();-
Para obter detalhes da API, consulte RejectAgreementPaymentRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como substituir um contrato de SaaS por uma nova oferta baseada em contrato.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. 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();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como substituir um teste gratuito de SaaS por um Contrato com Preços de Consumo (CCP).
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput, pollUntilEntitlementsAvailable } = require("./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. * * 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. * * 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 using Intent.REPLACE. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the free trial offer. * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the paid CCP offer. * - Term IDs (starting with "term-") — found in each offer's term list. */ // The agreementProposalId from the free trial offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-free-trial-agreement-proposal-identifier>"; // Term ID for the FreeTrialPricingTerm in the free trial offer. const FREE_TRIAL_PRICING_TERM_ID = "<your-free-trial-pricing-term-id>"; // Term ID for the LegalTerm in the free trial offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the paid CCP offer to convert to. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-ccp-agreement-proposal-identifier>"; // Term ID for the FixedUpfrontPricingTerm in the CCP offer. const FIXED_UPFRONT_PRICING_TERM_ID = "<your-fixed-upfront-pricing-term-id>"; // Term ID for the PaymentScheduleTerm in the CCP offer. const PAYMENT_SCHEDULE_TERM_ID = "<your-payment-schedule-term-id>"; // Term ID for the UsageBasedPricingTerm in the CCP offer. const USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the CCP offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the CCP offer. const NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; /** * 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. */ async function createSaaSFreeTrialAndReplaceWithCCP() { const client = new MarketplaceAgreementClient(); const legalTerm = { id: LEGAL_TERM_ID }; const freeTrialPricingTerm = { id: FREE_TRIAL_PRICING_TERM_ID }; // --- Step 1: Agreement with freeTrialPricingTerm --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [freeTrialPricingTerm, legalTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with freeTrialPricingTerm created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with freeTrialPricingTerm accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); // Wait for freeTrialPricingTerm agreement entitlements to become active before replacing. console.log("Waiting for freeTrialPricingTerm agreement entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, acceptAgreementRequestResponse.agreementId); console.log("freeTrialPricingTerm agreement entitlements are now active."); formatOutput(entitlementsResponse); // --- Step 2: Replace Agreement with freeTrialPricingTerm with Paid CCP Offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the free trial agreement. const usageBasedPricingTerm = { id: USAGE_BASED_PRICING_TERM_ID }; const fixedUpfrontPricingTerm = { id: FIXED_UPFRONT_PRICING_TERM_ID }; const paymentScheduleTerm = { id: PAYMENT_SCHEDULE_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; const newLegalTerm = { id: NEW_LEGAL_TERM_ID }; const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [usageBasedPricingTerm, fixedUpfrontPricingTerm, paymentScheduleTerm, validityTerm, newLegalTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: acceptAgreementRequestResponse.agreementId, }) ); console.log("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); console.log("Agreement with freeTrialPricingTerm replaced with paid CCP offer. New AgreementId: " + aarResponse.agreementId); } createSaaSFreeTrialAndReplaceWithCCP();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como substituir um termo de preço baseado no uso de SaaS e cancelar o contrato anterior.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, CancelAgreementCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput, pollUntilEntitlementsAvailable } = require("./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. * * Scenario: A buyer subscribes to a SaaS product with UsageBasedPricingTerm. * The buyer then converts to a different offer by replacing the existing agreement. * * Flow: * 1. Create and accept the initial agreement request with UBPT. * 2. Wait for entitlements to become active. * 3. Replace the agreement with a new offer using Intent.REPLACE. * 4. Cancel the new agreement using CancelAgreement. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the initial offer. * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new offer to replace to. * - Term IDs (starting with "term-") — found in each offer's term list. */ // The agreementProposalId from the initial offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the initial offer. const USAGE_BASED_PRICING_TERM_ID = "<your-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the initial offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // Term ID for the LegalTerm in the initial offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // The agreementProposalId from the new offer to replace to. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the new offer. const NEW_USAGE_BASED_PRICING_TERM_ID = "<your-new-usage-based-pricing-term-id>"; // Term ID for the ValidityTerm in the new offer. const NEW_VALIDITY_TERM_ID = "<your-new-validity-term-id>"; // Term ID for the LegalTerm in the new offer. const NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; /** * 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. */ async function replaceSaaSUbptAndCancel() { const client = new MarketplaceAgreementClient(); const usageBasedPricingTerm = { id: USAGE_BASED_PRICING_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; const legalTerm = { id: LEGAL_TERM_ID }; // --- Step 1: Create and accept the initial UBPT agreement request --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [usageBasedPricingTerm, validityTerm, legalTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); console.log("Agreement request with UBPT accepted. AgreementId: " + acceptAgreementRequestResponse.agreementId); // Wait for entitlements to become active before replacing. console.log("Waiting for entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, acceptAgreementRequestResponse.agreementId); console.log("Entitlements are now active."); formatOutput(entitlementsResponse); // --- Step 2: Replace the UBPT agreement with a new offer --- // Use Intent.REPLACE and sourceAgreementIdentifier to replace the existing agreement. const newUsageBasedPricingTerm = { id: NEW_USAGE_BASED_PRICING_TERM_ID }; const newValidityTerm = { id: NEW_VALIDITY_TERM_ID }; const newLegalTerm = { id: NEW_LEGAL_TERM_ID }; const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [newUsageBasedPricingTerm, newValidityTerm, newLegalTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: acceptAgreementRequestResponse.agreementId, }) ); console.log("Replace agreement request created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); const agreementIdWithTheNewOffer = aarResponse.agreementId; console.log("UBPT agreement replaced. New AgreementId: " + agreementIdWithTheNewOffer); // --- Step 3: Cancel the new agreement --- await client.send( new CancelAgreementCommand({ agreementId: agreementIdWithTheNewOffer, }) ); console.log("The new agreement has been cancelled. AgreementId: " + agreementIdWithTheNewOffer); } replaceSaaSUbptAndCancel();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como substituir um termo de preço baseado no uso da AMI e, ao mesmo tempo, manter o existente. ConfigurableUpfrontPricingTerm
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput, pollUntilEntitlementsAvailable } = require("./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. * * Scenario: An AMI product with USAGE pricing requires two agreements: * 1. An agreement with usageBasedPricingTerm — accepted first to establish the base agreement. * 2. An agreement with configurableUpfrontPricingTerm (CUPT) — accepted after the usageBasedPricingTerm agreement entitlements are active. * * This sample shows how to replace only the agreement with usageBasedPricingTerm with a * new offer without touching the existing agreement with configurableUpfrontPricingTerm (CUPT). * * Flow: * 1. Create and accept the initial agreement request with usageBasedPricingTerm. * 2. Create and accept the agreement request with configurableUpfrontPricingTerm (CUPT) (after usageBasedPricingTerm agreement entitlements are active). * 3. Replace the agreement with usageBasedPricingTerm with a new offer using Intent.REPLACE. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offers: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the initial offer. * - NEW_AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the new offer to replace to. * - Term IDs (starting with "term-") — found in each offer's term list. * - SELECTOR_VALUE — duration for the agreement (e.g., "P365D"). * - DIMENSION_1_KEY — dimension key defined in the CUPT term. */ // The agreementProposalId from the initial offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in the initial offer. const CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P365D" for 365 days). const SELECTOR_VALUE = "<your-selector-value>"; // Dimension key defined in the CUPT term. const DIMENSION_1_KEY = "<your-dimension-key>"; // Quantity for the dimension. const DIMENSION_1_VALUE = 1; // Term ID for the UsageBasedPricingTerm in the initial offer. const USAGE_TERM_ID = "<your-usage-term-id>"; // Term ID for the LegalTerm in the initial offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in the initial offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; // The agreementProposalId from the new offer to replace to. const NEW_AGREEMENT_PROPOSAL_IDENTIFIER = "<your-new-agreement-proposal-identifier>"; // Term ID for the UsageBasedPricingTerm in the new offer. const NEW_USAGE_TERM_ID = "<your-new-usage-term-id>"; // Term ID for the LegalTerm in the new offer. const NEW_LEGAL_TERM_ID = "<your-new-legal-term-id>"; // Term ID for the ValidityTerm in the new offer. const NEW_VALIDITY_TERM_ID = "<your-new-validity-term-id>"; /** * 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). */ async function replaceAmiUsageWhenCuptExists() { const client = new MarketplaceAgreementClient(); const usageTerm = { id: USAGE_TERM_ID }; const legalTerm = { id: LEGAL_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; // --- Step 1: Agreement with UBPT --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [usageTerm, legalTerm, validityTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with UBPT created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, }) ); const usageAgreementId = acceptAgreementRequestResponse.agreementId; console.log("Agreement request with UBPT accepted. AgreementId: " + usageAgreementId); // Wait for UBPT agreement entitlements to become active before creating the agreement with CUPT. console.log("Waiting for UBPT agreement entitlements to become active..."); const entitlementsResponse = await pollUntilEntitlementsAvailable(client, usageAgreementId); console.log("UBPT agreement entitlements are now active."); formatOutput(entitlementsResponse); // --- Step 2: Agreement with configurableUpfrontPricingTerm (CUPT) --- const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, ], }, }, }; const carResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, legalTerm, validityTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request with CUPT created. AgreementRequestId: " + carResponse.agreementRequestId); const aarResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carResponse.agreementRequestId, }) ); const cuptAgreementId = aarResponse.agreementId; console.log("Agreement request with CUPT accepted. AgreementId: " + cuptAgreementId); // Wait for CUPT agreement entitlements to become active before replacing usage. console.log("Waiting for CUPT agreement entitlements to become active..."); const cuptEntitlementsResponse = await pollUntilEntitlementsAvailable(client, cuptAgreementId); console.log("CUPT agreement entitlements are now active."); formatOutput(cuptEntitlementsResponse); // --- Step 3: Replace Agreement with usageBasedPricingTerm with a new offer --- const newUsageTerm = { id: NEW_USAGE_TERM_ID }; const newLegalTerm = { id: NEW_LEGAL_TERM_ID }; const newValidityTerm = { id: NEW_VALIDITY_TERM_ID }; // Use Intent.REPLACE and sourceAgreementIdentifier pointing to the usageBasedPricingTerm agreement only. // The agreement with configurableUpfrontPricingTerm (CUPT) is NOT affected by this replacement. const carReplaceResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "REPLACE", requestedTerms: [newUsageTerm, newLegalTerm, newValidityTerm], agreementProposalIdentifier: NEW_AGREEMENT_PROPOSAL_IDENTIFIER, sourceAgreementIdentifier: usageAgreementId, }) ); console.log("Replace agreement request created. AgreementRequestId: " + carReplaceResponse.agreementRequestId); const aarReplaceResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: carReplaceResponse.agreementRequestId, }) ); console.log("Agreement with UBPT replaced. New AgreementId: " + aarReplaceResponse.agreementId); } replaceAmiUsageWhenCuptExists();-
Para obter detalhes da API, consulte CreateAgreementRequesta Referência AWS SDK para JavaScript da API.
-
O exemplo de código a seguir mostra como atualizar os pedidos de compra após a aceitação do contrato.
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no repositório da Biblioteca de códigos da referência de API do AWS Marketplace
. const { MarketplaceAgreementClient, CreateAgreementRequestCommand, AcceptAgreementRequestCommand, ListAgreementChargesCommand, UpdatePurchaseOrdersCommand, } = require("@aws-sdk/client-marketplace-agreement"); const { generateClientToken, formatOutput } = require("./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. * * 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. * * Before running this sample, replace the placeholder constants below with values from * your AWS Marketplace offer: * - AGREEMENT_PROPOSAL_IDENTIFIER — the agreementProposalId from the offer. * - Term IDs (starting with "term-") — found in the offer's term list. * - SELECTOR_VALUE — duration for the agreement. * - DIMENSION_1_KEY — dimension key defined in the offer. * - PURCHASE_ORDER_REFERENCE — your internal purchase order number (e.g., "po-123456"). */ // Your internal purchase order reference number (e.g., "po-123456"). const PURCHASE_ORDER_REFERENCE = "po-123456"; // The agreementProposalId from the offer. const AGREEMENT_PROPOSAL_IDENTIFIER = "<your-agreement-proposal-identifier>"; // Term ID for the ConfigurableUpfrontPricingTerm in your offer. const CONFIGURABLE_UPFRONT_PRICING_TERM_ID = "<your-configurable-upfront-pricing-term-id>"; // Duration for the agreement (e.g., "P366D" for 366 days). const SELECTOR_VALUE = "<your-selector-value>"; // Dimension key and quantity defined in your offer. const DIMENSION_1_KEY = "<your-dimension-key>"; const DIMENSION_1_VALUE = 1; // Term ID for the LegalTerm in your offer. const LEGAL_TERM_ID = "<your-legal-term-id>"; // Term ID for the ValidityTerm in your offer. const VALIDITY_TERM_ID = "<your-validity-term-id>"; /** * 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. */ async function listAgreementChargesAndUpdatePurchaseOrders() { const client = new MarketplaceAgreementClient(); const configurableUpfrontPricingTerm = { id: CONFIGURABLE_UPFRONT_PRICING_TERM_ID, configuration: { configurableUpfrontPricingTermConfiguration: { selectorValue: SELECTOR_VALUE, dimensions: [ { dimensionKey: DIMENSION_1_KEY, dimensionValue: DIMENSION_1_VALUE }, ], }, }, }; const legalTerm = { id: LEGAL_TERM_ID }; const validityTerm = { id: VALIDITY_TERM_ID }; // --- Create Agreement --- const createAgreementRequestResponse = await client.send( new CreateAgreementRequestCommand({ clientToken: generateClientToken(), intent: "NEW", requestedTerms: [configurableUpfrontPricingTerm, legalTerm, validityTerm], agreementProposalIdentifier: AGREEMENT_PROPOSAL_IDENTIFIER, }) ); console.log("Agreement request created. AgreementRequestId: " + createAgreementRequestResponse.agreementRequestId); // --- Accept Agreement Request with Purchase Order --- // The chargeId is available from the CAR response's chargeSummary.expectedCharges. const chargeId = createAgreementRequestResponse.chargeSummary.expectedCharges[0].id; const purchaseOrderAtAcceptance = { chargeId: chargeId, purchaseOrderReference: PURCHASE_ORDER_REFERENCE, }; const acceptAgreementRequestResponse = await client.send( new AcceptAgreementRequestCommand({ agreementRequestId: createAgreementRequestResponse.agreementRequestId, purchaseOrders: [purchaseOrderAtAcceptance], }) ); const agreementId = acceptAgreementRequestResponse.agreementId; console.log("Agreement request accepted with purchase order reference '" + PURCHASE_ORDER_REFERENCE + "'. AgreementId: " + agreementId); // --- List Agreement Charges --- const listAgreementChargesResponse = await client.send( new ListAgreementChargesCommand({ agreementId: agreementId, }) ); console.log("All charges for agreement " + agreementId + ":"); formatOutput(listAgreementChargesResponse); // --- Update Purchase Order --- const firstCharge = listAgreementChargesResponse.items[0]; const purchaseOrder = { agreementId: agreementId, purchaseOrderReference: PURCHASE_ORDER_REFERENCE, chargeRevision: firstCharge.revision, chargeId: firstCharge.id, }; await client.send( new UpdatePurchaseOrdersCommand({ purchaseOrders: [purchaseOrder], }) ); console.log("Purchase order reference '" + PURCHASE_ORDER_REFERENCE + "' updated for ChargeId: " + firstCharge.id); // --- Verify Update --- const lacResponse = await client.send( new ListAgreementChargesCommand({ agreementId: agreementId, }) ); console.log("Verified updated charge:"); formatOutput(lacResponse.items[0]); } listAgreementChargesAndUpdatePurchaseOrders();-
Para obter detalhes da API, consulte UpdatePurchaseOrdersa Referência AWS SDK para JavaScript da API.
-