Utilizzare con un SDK GetOpportunityAWS - AWS Esempi di codice SDK

Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Utilizzare con un SDK GetOpportunityAWS

Gli esempi di codice seguenti mostrano come utilizzare GetOpportunity.

.NET
SDK per .NET

Ottieni un'opportunità.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // PDX-License-Identifier: Apache-2.0 using System; using Newtonsoft.Json; using Amazon; using Amazon.Runtime; using Amazon.PartnerCentralSelling; using Amazon.PartnerCentralSelling.Model; namespace AWSExample { class Program { static readonly string catalogToUse = "AWS"; static readonly string identifier = "O1111111"; static async Task Main(string[] args) { // Initialize credentials from .aws/credentials file var credentials = new Amazon.Runtime.CredentialManagement.SharedCredentialsFile(); if (credentials.TryGetProfile("default", out var profile)) { AWSCredentials awsCredentials = profile.GetAWSCredentials(credentials); var client = new AmazonPartnerCentralSellingClient(awsCredentials); var request = new GetOpportunityRequest { Catalog = catalogToUse, Identifier = identifier }; try { var response = await client.GetOpportunityAsync(request); Console.WriteLine(response.HttpStatusCode); string formattedJson = JsonConvert.SerializeObject(response, Formatting.Indented); Console.WriteLine(formattedJson); } catch(ValidationException ex) { Console.WriteLine("Validation error: " + ex.Message); } catch (AmazonPartnerCentralSellingException e) { Console.WriteLine("Failed:"); Console.WriteLine(e.RequestId); Console.WriteLine(e.ErrorCode); Console.WriteLine(e.Message); } } else { Console.WriteLine("Profile not found."); } } } }
  • Per i dettagli sulle API, consulta la GetOpportunitysezione AWS SDK per .NET API Reference.

Go
SDK per Go V2

Ottieni un'opportunità.

package main import ( "context" "encoding/json" "fmt" "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/partnercentralselling" ) func main() { config, err := config.LoadDefaultConfig(context.TODO()) if err != nil { log.Fatal(err) } config.Region = "us-east-1" client := partnercentralselling.NewFromConfig(config) output, err := client.GetOpportunity(context.TODO(), &partnercentralselling.GetOpportunityInput{ Identifier: aws.String("O1111111"), Catalog: aws.String("AWS"), }) if err != nil { log.Fatal(err) } log.Println("printing opportuniy...\n") jsonOutput, err := json.MarshalIndent(output, "", " ") fmt.Println(string(jsonOutput)) }
  • Per i dettagli sulle API, consulta la GetOpportunitysezione AWS SDK per Go API Reference.

Java
SDK per Java 2.x

Ottieni un'opportunità.

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.GetOpportunityRequest; import software.amazon.awssdk.services.partnercentralselling.model.GetOpportunityResponse; /* * Purpose * PC-API-08 Get updated Opportunity */ public class GetOpportunity { 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; GetOpportunityResponse response = getResponse(opportunityId); ReferenceCodesUtils.formatOutput(response); } public static GetOpportunityResponse getResponse(String opportunityId) { GetOpportunityRequest getOpportunityRequest = GetOpportunityRequest.builder() .catalog(Constants.CATALOG_TO_USE) .identifier(opportunityId) .build(); GetOpportunityResponse response = client.getOpportunity(getOpportunityRequest); return response; } }
  • Per i dettagli sulle API, consulta la GetOpportunitysezione AWS SDK for Java 2.x API Reference.

Python
SDK per Python (Boto3)

Ottieni 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 i dettagli sull'API, consulta GetOpportunity AWSSDK for Python (Boto3) API Reference.