更新机会的关联实体 - AWS SDK 代码示例

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

更新机会的关联实体

以下代码示例演示了如何:

  • 取消与旧实体的关联。

  • 关联新实体。

Java
适用于 Java 的 SDK 2.x
注意

还有更多相关信息 GitHub。查找完整的示例,学习如何在场景存储库中设置和运行。

更新机会的关联实体

package org.example; import static org.example.utils.Constants.*; import org.example.utils.Constants; import org.example.utils.ReferenceCodesUtils; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.partnercentralselling.PartnerCentralSellingClient; import software.amazon.awssdk.services.partnercentralselling.model.AssociateOpportunityRequest; import software.amazon.awssdk.services.partnercentralselling.model.AssociateOpportunityResponse; import software.amazon.awssdk.services.partnercentralselling.model.DisassociateOpportunityRequest; import software.amazon.awssdk.services.partnercentralselling.model.DisassociateOpportunityResponse; /* Purpose PC-API -17 Replacing a solution */ public class ReplaceSolution { static PartnerCentralSellingClient client = PartnerCentralSellingClient.builder() .region(Region.US_EAST_1) .credentialsProvider(DefaultCredentialsProvider.create()) .httpClient(ApacheHttpClient.builder().build()) .build(); public static void main(String[] args) { String opportunityId = args.length > 0 ? args[0] : OPPORTUNITY_ID; String entityType = "Solutions"; String originalEntityIdentifier = "S-0000000"; String newEntityIdentifier = "S-0011111"; disassociateOppornitityResponse(opportunityId, entityType, originalEntityIdentifier ); AssociateOpportunityResponse associateOpportunityResponse = associateOpportunityResponse(opportunityId, entityType, newEntityIdentifier ); ReferenceCodesUtils.formatOutput(associateOpportunityResponse); } private static AssociateOpportunityResponse associateOpportunityResponse(String opportunityId, String entityType, String entityIdentifier) { AssociateOpportunityRequest associateOpportunityRequest = AssociateOpportunityRequest.builder() .catalog(Constants.CATALOG_TO_USE) .opportunityIdentifier(opportunityId) .relatedEntityType(entityType) .relatedEntityIdentifier(entityIdentifier) .build(); AssociateOpportunityResponse response = client.associateOpportunity(associateOpportunityRequest); return response; } private static DisassociateOpportunityResponse disassociateOppornitityResponse(String opportunityId, String entityType, String entityIdentifier) { PartnerCentralSellingClient client = PartnerCentralSellingClient.builder() .region(Region.US_EAST_1) .credentialsProvider(DefaultCredentialsProvider.create()) .httpClient(ApacheHttpClient.builder().build()) .build(); DisassociateOpportunityRequest disassociateOpportunityRequest = DisassociateOpportunityRequest.builder() .catalog(Constants.CATALOG_TO_USE) .opportunityIdentifier(opportunityId) .relatedEntityType(entityType) .relatedEntityIdentifier(entityIdentifier) .build(); DisassociateOpportunityResponse response = client.disassociateOpportunity(disassociateOpportunityRequest); return response; } }
Python
适用于 Python 的 SDK(Boto3)
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

更新机会的关联实体

#!/usr/bin/env python """ Purpose PC-API -17 Replacing a solution """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def replace_solution(original_entity_identifier, new_entity_identifier, opportunityIdentifier): disassociate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : "Solutions", "RelatedEntityIdentifier" : original_entity_identifier } associate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : "Solutions", "RelatedEntityIdentifier" : new_entity_identifier } try: # Perform an API call response = partner_central_client.disassociate_opportunity(**disassociate_opportunity_request) response = partner_central_client.associate_opportunity(**associate_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): original_entity_identifier = "S-0049999" new_entity_identifier = "S-0050014" opportunityIdentifier = "O4397574" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Replacing a solution.") print("-" * 88) helper.pretty_print_datetime(replace_solution(original_entity_identifier, new_entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()