AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-05-01 · Documentation low

File: code-library/latest/ug/csharp_3_partnercentral-selling_code_examples.md

Summary

Added code examples for GetOpportunity and ListOpportunities API operations with credential handling

Security assessment

Added standard API usage examples showing credential retrieval from AWS profile. Demonstrates normal security practices but does not introduce new security features or address vulnerabilities.

Diff

diff --git a/code-library/latest/ug/csharp_3_partnercentral-selling_code_examples.md b/code-library/latest/ug/csharp_3_partnercentral-selling_code_examples.md
index a8d1a53be..dcb2c87ea 100644
--- a//code-library/latest/ug/csharp_3_partnercentral-selling_code_examples.md
+++ b//code-library/latest/ug/csharp_3_partnercentral-selling_code_examples.md
@@ -153,0 +154,145 @@ Create an opportunity.
+The following code example shows how to use `GetOpportunity`.
+
+**SDK for .NET**
+    
+
+Get an opportunity.
+    
+    
+    // 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.");
+                }
+            }
+        }
+    }
+    
+    
+
+  * For API details, see [GetOpportunity](https://docs.aws.amazon.com/goto/DotNetSDKV3/partnercentral-selling-2022-07-26/GetOpportunity) in _AWS SDK for .NET API Reference_. 
+
+
+
+
+The following code example shows how to use `ListOpportunities`.
+
+**SDK for .NET**
+    
+
+List opportunities.
+    
+    
+    // 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 = "Sandbox";
+            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 config = new AmazonPartnerCentralSellingConfig()
+                    //{
+                    //    ServiceURL = "https://partnercentral-selling.us-east-1.api.aws",
+                    //};
+                    //var client = new AmazonPartnerCentralSellingClient(awsCredentials, config);
+                    var client = new AmazonPartnerCentralSellingClient(awsCredentials);
+                    var request = new ListOpportunitiesRequest
+                    {
+                        Catalog = catalogToUse,
+                        MaxResults = 2
+                    };
+    
+                    try {
+                        var response = await client.ListOpportunitiesAsync(request);
+                        Console.WriteLine(response.HttpStatusCode);
+                        foreach (var opportunity in response.OpportunitySummaries)
+                        {
+                            Console.WriteLine("Opportunity id: " + opportunity.Id);
+                        }
+                        string formattedJson = JsonConvert.SerializeObject(response.OpportunitySummaries, 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.");
+                }
+            }
+        }
+    }
+    
+    
+
+  * For API details, see [ListOpportunities](https://docs.aws.amazon.com/goto/DotNetSDKV3/partnercentral-selling-2022-07-26/ListOpportunities) in _AWS SDK for .NET API Reference_. 
+
+
+
+