Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS
Esempi per Centrale Partner con SDK per Python (Boto3)
Gli esempi di codice seguenti mostrano come eseguire operazioni e implementare scenari comuni utilizzando AWS SDK per Python (Boto3) con Centrale Partner.
Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.
Scenari: esempi di codice che mostrano come eseguire un’attività specifica chiamando più funzioni all’interno dello stesso servizio o combinate con altri Servizi AWS.
Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.
Azioni
L’esempio di codice seguente mostra come utilizzare AssignOpportunity.
- SDK per Python (Boto3)
-
Riassegna un’opportunità esistente a un altro utente.
#!/usr/bin/env python """ Purpose PC-API-07 Assigning a new owner """ 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 assign_opportunity(identifier): assign_opportunity_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier, "Assignee": { "BusinessTitle": "OpportunityOwner", "Email": "test@test.com", "FirstName": "John", "LastName": "Doe" } } try: # Perform an API call response = partner_central_client.assign_opportunity(**assign_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O4236468" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Assigning a new owner to an opportunity.") print("-" * 88) helper.pretty_print_datetime(assign_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta AssignOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare AssociateOpportunity.
- SDK per Python (Boto3)
-
Crea un’associazione formale tra un’opportunità e varie entità correlate.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ 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 associate_opportunity(entity_type, entity_identifier, opportunityIdentifier): associate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : entity_type, "RelatedEntityIdentifier" : entity_identifier } try: # Perform an API call 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(): #entity_type = Solutions | AWSProducts | AWSMarketplaceOffers entity_type = "Solutions" entity_identifier = "S-0059717" opportunityIdentifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Associate Opportunity.") print("-" * 88) helper.pretty_print_datetime(associate_opportunity(entity_type, entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta AssociateOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare CreateOpportunity.
- SDK per Python (Boto3)
-
Crea un’opportunità.
#!/usr/bin/env python import boto3 import logging import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import utils.helpers as helper import utils.stringify_details as sd from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" def create_opportunity(partner_central_client): create_opportunity_request = helper.remove_nulls(sd.stringify_json("src/create_opportunity/createOpportunity.json")) try: # Perform an API call response = partner_central_client.create_opportunity(**create_opportunity_request) helper.pretty_print_datetime(response) # Retrieve the opportunity details get_response = partner_central_client.get_opportunity( Identifier=response["Id"], Catalog=CATALOG_TO_USE ) helper.pretty_print_datetime(get_response) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Create Opportunity.") print("-" * 88) partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) create_opportunity(partner_central_client) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta CreateOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare DisassociateOpportunity.
- SDK per Python (Boto3)
-
Rimuove un’associazione esistente tra un’opportunità e le entità correlate.
#!/usr/bin/env python """ Purpose PC-API -14 Removing a Solution PC-API -15 Removing an offer PC-API -16 Removing a product """ 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 disassociate_opportunity(entity_type, entity_identifier, opportunityIdentifier): disassociate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : entity_type, "RelatedEntityIdentifier" : entity_identifier } try: # Perform an API call response = partner_central_client.disassociate_opportunity(**disassociate_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): #entity_type = Solutions | AWSProducts | AWSMarketplaceOffers entity_type = "Solutions" entity_identifier = "S-0049999" opportunityIdentifier = "O4397574" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(disassociate_opportunity(entity_type, entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta DisassociateOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare GetAwsOpportunitySummary.
- SDK per Python (Boto3)
-
Per recuperare un riepilogo di un’opportunità AWS.
#!/usr/bin/env python """ Purpose PC-API-25 Retrieves a summary of an AWS Opportunity. LifeCycle.ReviewStatus=Approved """ 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 get_opportunity(identifier): get_opportunity_request ={ "Catalog": CATALOG_TO_USE, "RelatedOpportunityIdentifier": identifier } try: # Perform an API call response = partner_central_client.get_aws_opportunity_summary(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get AWS Opportunity summary.") print("-" * 88) helper.pretty_print_datetime(get_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta GetAwsOpportunitySummary nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare GetEngagementInvitation.
- SDK per Python (Boto3)
-
Per recuperare i dettagli di un invito di coinvolgimento condiviso da AWS con un partner.
#!/usr/bin/env python """ Purpose PC-API-22 GetOpportunityEngagementInvitation - Retrieves details of a specific engagement invitation. This operation allows partners to view the invitation and its associated information, such as the customer, project, and lifecycle details. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity_engagement_invitation(identifier): get_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier } try: # Perform an API call response = partner_central_client.get_engagement_invitation(**get_opportunity_engagement_invitation_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): identifier = "arn:aws:partnercentral-selling:us-east-1:aws:catalog/Sandbox/engagement-invitation/engi-0000000IS0Qga" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Given the ARN identifier, retrieve details of Opportunity Engagement Invitation.") print("-" * 88) helper.pretty_print_datetime(get_opportunity_engagement_invitation(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta GetEngagementInvitation nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare GetOpportunity.
- SDK per Python (Boto3)
-
Ottiene un’opportunità.
#!/usr/bin/env python """ Purpose PC-API -08 Get updated Opportunity given opportunity id """ 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 get_opportunity(identifier): get_opportunity_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier } try: # Perform an API call response = partner_central_client.get_opportunity(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(get_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta GetOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare ListEngagementInvitations.
- SDK per Python (Boto3)
-
Recupera un elenco di inviti di coinvolgimento inviati al partner.
#!/usr/bin/env python """ Purpose PC-API-21 ListEngagementInvitations - Retrieves a list of engagement invitations based on specified criteria. This operation allows partners to view all invitations to engagement. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def list_engagement_invitations(): list_engagement_invitations_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_engagement_invitations(**list_engagement_invitations_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Retrieve list of Engagement Invitations.") print("-" * 88) helper.pretty_print_datetime(list_engagement_invitations()) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta ListEngagementInvitations nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare ListOpportunities.
- SDK per Python (Boto3)
-
Elenca le opportunità.
#!/usr/bin/env python """ Purpose PC-API -18 Getting list of Opportunities """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_list_of_opportunities(): opportunity_list = [] list_opportunities_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_opportunities(**list_opportunities_request) opportunity_list.extend(response["OpportunitySummaries"]) while "NextToken" in response and response["NextToken"] is not None: list_opportunities_request["NextToken"] = response["NextToken"] response = partner_central_client.list_opportunities(**list_opportunities_request) opportunity_list.extend(response["OpportunitySummaries"]) return opportunity_list except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Getting list of Opportunities.") print("-" * 88) helper.pretty_print_datetime(get_list_of_opportunities()) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta ListOpportunities nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare ListSolutions.
- SDK per Python (Boto3)
-
Recupera un elenco di soluzioni per i partner che il partner ha registrato in Centrale Partner.
#!/usr/bin/env python """ Purpose PC-API-10 Getting list of solutions """ 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 get_list_of_solutions(): list_solutions_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_solutions(**list_solutions_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Getting list of solutions.") print("-" * 88) helper.pretty_print_datetime(get_list_of_solutions()) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta ListSolutions nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare RejectEngagementInvitation.
- SDK per Python (Boto3)
-
Per rifiutare un invito di coinvolgimento condiviso da AWS.
#!/usr/bin/env python """ Purpose PC-API-05 AWS Originated AO rejection - RejectOpportunityEngagementInvitation - Rejects a engagement invitation. This action indicates that the partner does not wish to participate in the engagement and provides a reason for the rejection. Upon rejection, a OpportunityEngagementInvitationRejected event is triggered. Subsequently, the invitation will no longer be available for the partner to act on. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def reject_opportunity_engagement_invitation(identifier, reject_reason): reject_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier, "RejectionReason": reject_reason } try: # Perform an API call response = partner_central_client.reject_engagement_invitation(**reject_opportunity_engagement_invitation_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): identifier = "arn:aws:partnercentral:us-east-1::catalog/Sandbox/engagement-invitation/engi-0000002isviga" reject_reason = "Customer problem unclear" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Given the ARN identifier and reject reason, reject the Opportunity Engagement Invitation.") print("-" * 88) helper.pretty_print_datetime(reject_opportunity_engagement_invitation(identifier, reject_reason)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta RejectEngagementInvitation nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare StartEngagementByAcceptingInvitationTask.
- SDK per Python (Boto3)
-
Avvia il coinvolgimento accettando un invito di coinvolgimento.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ 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 get_opportunity(identifier): get_opportunity_request ={ "Identifier": identifier, "Catalog": CATALOG_TO_USE } try: # Perform an API call response = partner_central_client.get_engagement_invitation(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def start_engagement_by_accepting_invitation_task(identifier): response = get_opportunity(identifier) if ( response['Status'] == 'PENDING') : accept_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier" : identifier, "ClientToken": "test-123456" } try: # Perform an API call response = partner_central_client.start_engagement_by_accepting_invitation_task(**accept_opportunity_engagement_invitation_request) return response except ClientError as err: # Catch all client exceptions print(err.response) return None else: return None def usage_demo(): identifier = "arn:aws:partnercentral:us-east-1::catalog/Sandbox/engagement-invitation/engi-0000002isusga" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(start_engagement_by_accepting_invitation_task(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta StartEngagementByAcceptingInvitationTask nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare StartEngagementFromOpportunityTask.
- SDK per Python (Boto3)
-
Avvia il processo di coinvolgimento partendo da un’opportunità esistente accettando l’invito di coinvolgimento e creando un’opportunità corrispondente nel sistema del partner.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ 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 start_engagement_from_opportunity_task(identifier): start_engagement_from_opportunity_task_request ={ "AwsSubmission": { "InvolvementType": "Co-Sell", "Visibility": "Full" }, "Catalog": CATALOG_TO_USE, "Identifier" : identifier, "ClientToken": "test-annjqwesdsd99" } try: # Perform an API call response = partner_central_client.start_engagement_from_opportunity_task(**start_engagement_from_opportunity_task_request) return response except ClientError as err: # Catch all client exceptions print(err.response) return None def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Start Engagement from Opportunity Task.") print("-" * 88) helper.pretty_print_datetime(start_engagement_from_opportunity_task(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta StartEngagementFromOpportunityTask nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
L’esempio di codice seguente mostra come utilizzare UpdateOpportunity.
- SDK per Python (Boto3)
-
Aggiorna un’opportunità.
#!/usr/bin/env python """ Purpose PC-API-2 Updating Partner Originated Opportunity """ import logging import boto3 import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import utils.helpers as helper from botocore.client import ClientError import utils.stringify_details as sd from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity(identifier): get_opportunity_request ={ "Identifier": identifier, "Catalog": CATALOG_TO_USE } try: # Perform an API call response = partner_central_client.get_opportunity(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def update_opportunity(): update_opportunity_request_orig = sd.stringify_json("src/update_opportunity/update_opportunity_technical_validation.json") update_opportunity_request = helper.remove_nulls(update_opportunity_request_orig) try: # Perform an API call response = partner_central_client.update_opportunity(**update_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def update_opportunity_if_eligible(identifier): response = get_opportunity(identifier) if response is not None: return update_opportunity() else: print("Failed to retrieve opportunity details") def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Updating opportunity.") print("-" * 88) helper.pretty_print_datetime(update_opportunity_if_eligible(identifier)) if __name__ == "__main__": usage_demo()-
Per informazioni dettagliate sull’API, consulta UpdateOpportunity nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-
Scenari
L’esempio di codice seguente mostra come:
Annullare l’associazione di una vecchia entità.
Associare una nuova entità.
- SDK per Python (Boto3)
-
Nota
Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice AWS
. Aggiornare l’entità associata di un’opportunità
#!/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()-
Per informazioni dettagliate sull’API, consulta i seguenti argomenti nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).
-