AWS Support ejemplos que utilizan AWS SDK for .NET - Ejemplos de código de AWS SDK

Hay más AWS SDK ejemplos disponibles en el GitHub repositorio de AWS Doc SDK Examples.

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

AWS Support ejemplos que utilizan AWS SDK for .NET

Los siguientes ejemplos de código muestran cómo realizar acciones e implementar escenarios comunes mediante el uso del AWS SDK for .NET with AWS Support.

Las acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Mientras las acciones muestran cómo llamar a las funciones de servicio individuales, es posible ver las acciones en contexto en los escenarios relacionados y en los ejemplos entre servicios.

Los escenarios son ejemplos de código que muestran cómo llevar a cabo una tarea específica llamando a varias funciones dentro del mismo servicio.

Cada ejemplo incluye un enlace a GitHub, donde puede encontrar instrucciones sobre cómo configurar y ejecutar el código en su contexto.

Introducción

En los siguientes ejemplos de código se muestra cómo empezar a utilizar AWS Glue.

AWS SDK for .NET
nota

Hay más información GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

using Amazon.AWSSupport; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; public static class HelloSupport { static async Task Main(string[] args) { // Use the AWS .NET Core Setup package to set up dependency injection for the AWS Support service. // Use your AWS profile name, or leave it blank to use the default profile. // You must have one of the following AWS Support plans: Business, Enterprise On-Ramp, or Enterprise. Otherwise, an exception will be thrown. using var host = Host.CreateDefaultBuilder(args) .ConfigureServices((_, services) => services.AddAWSService<IAmazonAWSSupport>() ).Build(); // Now the client is available for injection. var supportClient = host.Services.GetRequiredService<IAmazonAWSSupport>(); // You can use await and any of the async methods to get a response. var response = await supportClient.DescribeServicesAsync(); Console.WriteLine($"\tHello AWS Support! There are {response.Services.Count} services available."); } }
  • Para API obtener más información, consulte DescribeServicesla AWS SDK for .NET APIReferencia.

Acciones

En el siguiente ejemplo de código, se muestra cómo usar AddAttachmentsToSet.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; }
  • Para API obtener más información, consulte AddAttachmentsToSetla AWS SDK for .NET APIReferencia.

En el siguiente ejemplo de código, se muestra cómo usar AddCommunicationToCase.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Add communication to a case, including optional attachment set ID and CC email addresses. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <param name="body">Body text of the communication.</param> /// <param name="attachmentSetId">Optional Id for an attachment set.</param> /// <param name="ccEmailAddresses">Optional list of CC email addresses.</param> /// <returns>True if successful.</returns> public async Task<bool> AddCommunicationToCase(string caseId, string body, string? attachmentSetId = null, List<string>? ccEmailAddresses = null) { var response = await _amazonSupport.AddCommunicationToCaseAsync( new AddCommunicationToCaseRequest() { CaseId = caseId, CommunicationBody = body, AttachmentSetId = attachmentSetId, CcEmailAddresses = ccEmailAddresses }); return response.Result; }

En el siguiente ejemplo de código, se muestra cómo usar CreateCase.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Create a new support case. /// </summary> /// <param name="serviceCode">Service code for the new case.</param> /// <param name="categoryCode">Category for the new case.</param> /// <param name="severityCode">Severity code for the new case.</param> /// <param name="subject">Subject of the new case.</param> /// <param name="body">Body text of the new case.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <param name="attachmentSetId">Optional Id for an attachment set for the new case.</param> /// <param name="issueType">Optional issue type for the new case. Options are "customer-service" or "technical".</param> /// <returns>The caseId of the new support case.</returns> public async Task<string> CreateCase(string serviceCode, string categoryCode, string severityCode, string subject, string body, string language = "en", string? attachmentSetId = null, string issueType = "customer-service") { var response = await _amazonSupport.CreateCaseAsync( new CreateCaseRequest() { ServiceCode = serviceCode, CategoryCode = categoryCode, SeverityCode = severityCode, Subject = subject, Language = language, AttachmentSetId = attachmentSetId, IssueType = issueType, CommunicationBody = body }); return response.CaseId; }
  • Para API obtener más información, consulte CreateCasela AWS SDK for .NET APIReferencia.

En el siguiente ejemplo de código, se muestra cómo usar DescribeAttachment.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Get description of a specific attachment. /// </summary> /// <param name="attachmentId">Id of the attachment, usually fetched by describing the communications of a case.</param> /// <returns>The attachment object.</returns> public async Task<Attachment> DescribeAttachment(string attachmentId) { var response = await _amazonSupport.DescribeAttachmentAsync( new DescribeAttachmentRequest() { AttachmentId = attachmentId }); return response.Attachment; }
  • Para API obtener más información, consulte DescribeAttachmentla AWS SDK for .NET APIReferencia.

En el siguiente ejemplo de código, se muestra cómo usar DescribeCases.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Get case details for a list of case ids, optionally with date filters. /// </summary> /// <param name="caseIds">The list of case IDs.</param> /// <param name="displayId">Optional display ID.</param> /// <param name="includeCommunication">True to include communication. Defaults to true.</param> /// <param name="includeResolvedCases">True to include resolved cases. Defaults to false.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>A list of CaseDetails.</returns> public async Task<List<CaseDetails>> DescribeCases(List<string> caseIds, string? displayId = null, bool includeCommunication = true, bool includeResolvedCases = false, DateTime? afterTime = null, DateTime? beforeTime = null, string language = "en") { var results = new List<CaseDetails>(); var paginateCases = _amazonSupport.Paginators.DescribeCases( new DescribeCasesRequest() { CaseIdList = caseIds, DisplayId = displayId, IncludeCommunications = includeCommunication, IncludeResolvedCases = includeResolvedCases, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s"), Language = language }); // Get the entire list using the paginator. await foreach (var cases in paginateCases.Cases) { results.Add(cases); } return results; }
  • Para API obtener más información, consulte DescribeCasesla AWS SDK for .NET APIReferencia.

En el siguiente ejemplo de código, se muestra cómo usar DescribeCommunications.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Describe the communications for a case, optionally with a date filter. /// </summary> /// <param name="caseId">The ID of the support case.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <returns>The list of communications for the case.</returns> public async Task<List<Communication>> DescribeCommunications(string caseId, DateTime? afterTime = null, DateTime? beforeTime = null) { var results = new List<Communication>(); var paginateCommunications = _amazonSupport.Paginators.DescribeCommunications( new DescribeCommunicationsRequest() { CaseId = caseId, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s") }); // Get the entire list using the paginator. await foreach (var communications in paginateCommunications.Communications) { results.Add(communications); } return results; }

En el siguiente ejemplo de código, se muestra cómo usar DescribeServices.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Get the descriptions of AWS services. /// </summary> /// <param name="name">Optional language for services. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of AWS service descriptions.</returns> public async Task<List<Service>> DescribeServices(string language = "en") { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = language }); return response.Services; }
  • Para API obtener más información, consulte DescribeServicesla AWS SDK for .NET APIReferencia.

En el siguiente ejemplo de código, se muestra cómo usar DescribeSeverityLevels.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Get the descriptions of support severity levels. /// </summary> /// <param name="name">Optional language for severity levels. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of support severity levels.</returns> public async Task<List<SeverityLevel>> DescribeSeverityLevels(string language = "en") { var response = await _amazonSupport.DescribeSeverityLevelsAsync( new DescribeSeverityLevelsRequest() { Language = language }); return response.SeverityLevels; }

En el siguiente ejemplo de código, se muestra cómo usar ResolveCase.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

/// <summary> /// Resolve a support case by caseId. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <returns>The final status of the case after resolving.</returns> public async Task<string> ResolveCase(string caseId) { var response = await _amazonSupport.ResolveCaseAsync( new ResolveCaseRequest() { CaseId = caseId }); return response.FinalCaseStatus; }
  • Para API obtener más información, consulte ResolveCasela AWS SDK for .NET APIReferencia.

Escenarios

En el siguiente ejemplo de código, se muestra cómo:

  • Obtenga y muestre los servicios disponibles y los niveles de gravedad de los casos.

  • Cree un caso de asistencia mediante un servicio, una categoría y un nivel de gravedad seleccionados.

  • Obtenga y muestre una lista de casos abiertos para el día actual.

  • Añada una serie de archivos adjuntos y una comunicación al nuevo caso.

  • Describa el nuevo archivo adjunto y la comunicación del caso.

  • Resuelva el caso.

  • Obtenga y muestre una lista de casos resueltos para el día actual.

AWS SDK for .NET
nota

Hay más información sobre GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

Ejecutar un escenario interactivo en un símbolo del sistema.

/// <summary> /// Hello AWS Support example. /// </summary> public static class SupportCaseScenario { /* Before running this .NET code example, set up your development environment, including your credentials. To use the AWS Support API, you must have one of the following AWS Support plans: Business, Enterprise On-Ramp, or Enterprise. This .NET example performs the following tasks: 1. Get and display services. Select a service from the list. 2. Select a category from the selected service. 3. Get and display severity levels and select a severity level from the list. 4. Create a support case using the selected service, category, and severity level. 5. Get and display a list of open support cases for the current day. 6. Create an attachment set with a sample text file to add to the case. 7. Add a communication with the attachment to the support case. 8. List the communications of the support case. 9. Describe the attachment set. 10. Resolve the support case. 11. Get a list of resolved cases for the current day. */ private static SupportWrapper _supportWrapper = null!; static async Task Main(string[] args) { // Set up dependency injection for the AWS Support service. // Use your AWS profile name, or leave it blank to use the default profile. using var host = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.AddFilter("System", LogLevel.Debug) .AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information) .AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace)) .ConfigureServices((_, services) => services.AddAWSService<IAmazonAWSSupport>(new AWSOptions() { Profile = "default" }) .AddTransient<SupportWrapper>() ) .Build(); var logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger(typeof(SupportCaseScenario)); _supportWrapper = host.Services.GetRequiredService<SupportWrapper>(); Console.WriteLine(new string('-', 80)); Console.WriteLine("Welcome to the AWS Support case example scenario."); Console.WriteLine(new string('-', 80)); try { var apiSupported = await _supportWrapper.VerifySubscription(); if (!apiSupported) { logger.LogError("You must have a Business, Enterprise On-Ramp, or Enterprise Support " + "plan to use the AWS Support API. \n\tPlease upgrade your subscription to run these examples."); return; } var service = await DisplayAndSelectServices(); var category = DisplayAndSelectCategories(service); var severityLevel = await DisplayAndSelectSeverity(); var caseId = await CreateSupportCase(service, category, severityLevel); await DescribeTodayOpenCases(); var attachmentSetId = await CreateAttachmentSet(); await AddCommunicationToCase(attachmentSetId, caseId); var attachmentId = await ListCommunicationsForCase(caseId); await DescribeCaseAttachment(attachmentId); await ResolveCase(caseId); await DescribeTodayResolvedCases(); Console.WriteLine(new string('-', 80)); Console.WriteLine("AWS Support case example scenario complete."); Console.WriteLine(new string('-', 80)); } catch (Exception ex) { logger.LogError(ex, "There was a problem executing the scenario."); } } /// <summary> /// List some available services from AWS Support, and select a service for the example. /// </summary> /// <returns>The selected service.</returns> private static async Task<Service> DisplayAndSelectServices() { Console.WriteLine(new string('-', 80)); var services = await _supportWrapper.DescribeServices(); Console.WriteLine($"AWS Support client returned {services.Count} services."); Console.WriteLine($"1. Displaying first 10 services:"); for (int i = 0; i < 10 && i < services.Count; i++) { Console.WriteLine($"\t{i + 1}. {services[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > services.Count) { Console.WriteLine( "Select an example support service by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return services[choiceNumber - 1]; } /// <summary> /// List the available categories for a service and select a category for the example. /// </summary> /// <param name="service">Service to use for displaying categories.</param> /// <returns>The selected category.</returns> private static Category DisplayAndSelectCategories(Service service) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"2. Available support categories for Service \"{service.Name}\":"); for (int i = 0; i < service.Categories.Count; i++) { Console.WriteLine($"\t{i + 1}. {service.Categories[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > service.Categories.Count) { Console.WriteLine( "Select an example support category by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return service.Categories[choiceNumber - 1]; } /// <summary> /// List available severity levels from AWS Support, and select a level for the example. /// </summary> /// <returns>The selected severity level.</returns> private static async Task<SeverityLevel> DisplayAndSelectSeverity() { Console.WriteLine(new string('-', 80)); var severityLevels = await _supportWrapper.DescribeSeverityLevels(); Console.WriteLine($"3. Get and display available severity levels:"); for (int i = 0; i < 10 && i < severityLevels.Count; i++) { Console.WriteLine($"\t{i + 1}. {severityLevels[i].Name}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > severityLevels.Count) { Console.WriteLine( "Select an example severity level by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } Console.WriteLine(new string('-', 80)); return severityLevels[choiceNumber - 1]; } /// <summary> /// Create an example support case. /// </summary> /// <param name="service">Service to use for the new case.</param> /// <param name="category">Category to use for the new case.</param> /// <param name="severity">Severity to use for the new case.</param> /// <returns>The caseId of the new support case.</returns> private static async Task<string> CreateSupportCase(Service service, Category category, SeverityLevel severity) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"4. Create an example support case" + $" with the following settings:" + $" \n\tService: {service.Name}, Category: {category.Name} " + $"and Severity Level: {severity.Name}."); var caseId = await _supportWrapper.CreateCase(service.Code, category.Code, severity.Code, "Example case for testing, ignore.", "This is my example support case."); Console.WriteLine($"\tNew case created with ID {caseId}"); Console.WriteLine(new string('-', 80)); return caseId; } /// <summary> /// List open cases for the current day. /// </summary> /// <returns>Async task.</returns> private static async Task DescribeTodayOpenCases() { Console.WriteLine($"5. List the open support cases for the current day."); // Describe the cases. If it is empty, try again and allow time for the new case to appear. List<CaseDetails> currentOpenCases = null!; while (currentOpenCases == null || currentOpenCases.Count == 0) { Thread.Sleep(1000); currentOpenCases = await _supportWrapper.DescribeCases( new List<string>(), null, false, false, DateTime.UtcNow.Date, DateTime.UtcNow); } foreach (var openCase in currentOpenCases) { Console.WriteLine($"\tCase: {openCase.CaseId} created {openCase.TimeCreated}"); } Console.WriteLine(new string('-', 80)); } /// <summary> /// Create an attachment set for a support case. /// </summary> /// <returns>The attachment set id.</returns> private static async Task<string> CreateAttachmentSet() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"6. Create an attachment set for a support case."); var fileName = "example_attachment.txt"; // Create the file if it does not already exist. if (!File.Exists(fileName)) { await using StreamWriter sw = File.CreateText(fileName); await sw.WriteLineAsync( "This is a sample file for attachment to a support case."); } await using var ms = new MemoryStream(await File.ReadAllBytesAsync(fileName)); var attachmentSetId = await _supportWrapper.AddAttachmentToSet( ms, fileName); Console.WriteLine($"\tNew attachment set created with id: \n\t{attachmentSetId.Substring(0, 65)}..."); Console.WriteLine(new string('-', 80)); return attachmentSetId; } /// <summary> /// Add an attachment set and communication to a case. /// </summary> /// <param name="attachmentSetId">Id of the attachment set.</param> /// <param name="caseId">Id of the case to receive the attachment set.</param> /// <returns>Async task.</returns> private static async Task AddCommunicationToCase(string attachmentSetId, string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"7. Add attachment set and communication to {caseId}."); await _supportWrapper.AddCommunicationToCase( caseId, "This is an example communication added to a support case.", attachmentSetId); Console.WriteLine($"\tNew attachment set and communication added to {caseId}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// List the communications for a case. /// </summary> /// <param name="caseId">Id of the case to describe.</param> /// <returns>An attachment id.</returns> private static async Task<string> ListCommunicationsForCase(string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"8. List communications for case {caseId}."); var communications = await _supportWrapper.DescribeCommunications(caseId); var attachmentId = ""; foreach (var communication in communications) { Console.WriteLine( $"\tCommunication created on: {communication.TimeCreated} has {communication.AttachmentSet.Count} attachments."); if (communication.AttachmentSet.Any()) { attachmentId = communication.AttachmentSet.First().AttachmentId; } } Console.WriteLine(new string('-', 80)); return attachmentId; } /// <summary> /// Describe an attachment by id. /// </summary> /// <param name="attachmentId">Id of the attachment to describe.</param> /// <returns>Async task.</returns> private static async Task DescribeCaseAttachment(string attachmentId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"9. Describe the attachment set."); var attachment = await _supportWrapper.DescribeAttachment(attachmentId); var data = Encoding.ASCII.GetString(attachment.Data.ToArray()); Console.WriteLine($"\tAttachment includes {attachment.FileName} with data: \n\t{data}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// Resolve the support case. /// </summary> /// <param name="caseId">Id of the case to resolve.</param> /// <returns>Async task.</returns> private static async Task ResolveCase(string caseId) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"10. Resolve case {caseId}."); var status = await _supportWrapper.ResolveCase(caseId); Console.WriteLine($"\tCase {caseId} has final status {status}"); Console.WriteLine(new string('-', 80)); } /// <summary> /// List resolved cases for the current day. /// </summary> /// <returns>Async Task.</returns> private static async Task DescribeTodayResolvedCases() { Console.WriteLine(new string('-', 80)); Console.WriteLine($"11. List the resolved support cases for the current day."); var currentCases = await _supportWrapper.DescribeCases( new List<string>(), null, false, true, DateTime.UtcNow.Date, DateTime.UtcNow); foreach (var currentCase in currentCases) { if (currentCase.Status == "resolved") { Console.WriteLine( $"\tCase: {currentCase.CaseId}: status {currentCase.Status}"); } } Console.WriteLine(new string('-', 80)); } }

Métodos envoltorios utilizados por el escenario para AWS Support las acciones.

/// <summary> /// Wrapper methods to use AWS Support for working with support cases. /// </summary> public class SupportWrapper { private readonly IAmazonAWSSupport _amazonSupport; public SupportWrapper(IAmazonAWSSupport amazonSupport) { _amazonSupport = amazonSupport; } /// <summary> /// Get the descriptions of AWS services. /// </summary> /// <param name="name">Optional language for services. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of AWS service descriptions.</returns> public async Task<List<Service>> DescribeServices(string language = "en") { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = language }); return response.Services; } /// <summary> /// Get the descriptions of support severity levels. /// </summary> /// <param name="name">Optional language for severity levels. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>The list of support severity levels.</returns> public async Task<List<SeverityLevel>> DescribeSeverityLevels(string language = "en") { var response = await _amazonSupport.DescribeSeverityLevelsAsync( new DescribeSeverityLevelsRequest() { Language = language }); return response.SeverityLevels; } /// <summary> /// Create a new support case. /// </summary> /// <param name="serviceCode">Service code for the new case.</param> /// <param name="categoryCode">Category for the new case.</param> /// <param name="severityCode">Severity code for the new case.</param> /// <param name="subject">Subject of the new case.</param> /// <param name="body">Body text of the new case.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <param name="attachmentSetId">Optional Id for an attachment set for the new case.</param> /// <param name="issueType">Optional issue type for the new case. Options are "customer-service" or "technical".</param> /// <returns>The caseId of the new support case.</returns> public async Task<string> CreateCase(string serviceCode, string categoryCode, string severityCode, string subject, string body, string language = "en", string? attachmentSetId = null, string issueType = "customer-service") { var response = await _amazonSupport.CreateCaseAsync( new CreateCaseRequest() { ServiceCode = serviceCode, CategoryCode = categoryCode, SeverityCode = severityCode, Subject = subject, Language = language, AttachmentSetId = attachmentSetId, IssueType = issueType, CommunicationBody = body }); return response.CaseId; } /// <summary> /// Add an attachment to a set, or create a new attachment set if one does not exist. /// </summary> /// <param name="data">The data for the attachment.</param> /// <param name="fileName">The file name for the attachment.</param> /// <param name="attachmentSetId">Optional setId for the attachment. Creates a new attachment set if empty.</param> /// <returns>The setId of the attachment.</returns> public async Task<string> AddAttachmentToSet(MemoryStream data, string fileName, string? attachmentSetId = null) { var response = await _amazonSupport.AddAttachmentsToSetAsync( new AddAttachmentsToSetRequest { AttachmentSetId = attachmentSetId, Attachments = new List<Attachment> { new Attachment { Data = data, FileName = fileName } } }); return response.AttachmentSetId; } /// <summary> /// Get description of a specific attachment. /// </summary> /// <param name="attachmentId">Id of the attachment, usually fetched by describing the communications of a case.</param> /// <returns>The attachment object.</returns> public async Task<Attachment> DescribeAttachment(string attachmentId) { var response = await _amazonSupport.DescribeAttachmentAsync( new DescribeAttachmentRequest() { AttachmentId = attachmentId }); return response.Attachment; } /// <summary> /// Add communication to a case, including optional attachment set ID and CC email addresses. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <param name="body">Body text of the communication.</param> /// <param name="attachmentSetId">Optional Id for an attachment set.</param> /// <param name="ccEmailAddresses">Optional list of CC email addresses.</param> /// <returns>True if successful.</returns> public async Task<bool> AddCommunicationToCase(string caseId, string body, string? attachmentSetId = null, List<string>? ccEmailAddresses = null) { var response = await _amazonSupport.AddCommunicationToCaseAsync( new AddCommunicationToCaseRequest() { CaseId = caseId, CommunicationBody = body, AttachmentSetId = attachmentSetId, CcEmailAddresses = ccEmailAddresses }); return response.Result; } /// <summary> /// Describe the communications for a case, optionally with a date filter. /// </summary> /// <param name="caseId">The ID of the support case.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <returns>The list of communications for the case.</returns> public async Task<List<Communication>> DescribeCommunications(string caseId, DateTime? afterTime = null, DateTime? beforeTime = null) { var results = new List<Communication>(); var paginateCommunications = _amazonSupport.Paginators.DescribeCommunications( new DescribeCommunicationsRequest() { CaseId = caseId, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s") }); // Get the entire list using the paginator. await foreach (var communications in paginateCommunications.Communications) { results.Add(communications); } return results; } /// <summary> /// Get case details for a list of case ids, optionally with date filters. /// </summary> /// <param name="caseIds">The list of case IDs.</param> /// <param name="displayId">Optional display ID.</param> /// <param name="includeCommunication">True to include communication. Defaults to true.</param> /// <param name="includeResolvedCases">True to include resolved cases. Defaults to false.</param> /// <param name="afterTime">The optional start date for a filtered search.</param> /// <param name="beforeTime">The optional end date for a filtered search.</param> /// <param name="language">Optional language support for your case. /// Currently Chinese (“zh”), English ("en"), Japanese ("ja") and Korean (“ko”) are supported.</param> /// <returns>A list of CaseDetails.</returns> public async Task<List<CaseDetails>> DescribeCases(List<string> caseIds, string? displayId = null, bool includeCommunication = true, bool includeResolvedCases = false, DateTime? afterTime = null, DateTime? beforeTime = null, string language = "en") { var results = new List<CaseDetails>(); var paginateCases = _amazonSupport.Paginators.DescribeCases( new DescribeCasesRequest() { CaseIdList = caseIds, DisplayId = displayId, IncludeCommunications = includeCommunication, IncludeResolvedCases = includeResolvedCases, AfterTime = afterTime?.ToString("s"), BeforeTime = beforeTime?.ToString("s"), Language = language }); // Get the entire list using the paginator. await foreach (var cases in paginateCases.Cases) { results.Add(cases); } return results; } /// <summary> /// Resolve a support case by caseId. /// </summary> /// <param name="caseId">Id for the support case.</param> /// <returns>The final status of the case after resolving.</returns> public async Task<string> ResolveCase(string caseId) { var response = await _amazonSupport.ResolveCaseAsync( new ResolveCaseRequest() { CaseId = caseId }); return response.FinalCaseStatus; } /// <summary> /// Verify the support level for AWS Support API access. /// </summary> /// <returns>True if the subscription level supports API access.</returns> public async Task<bool> VerifySubscription() { try { var response = await _amazonSupport.DescribeServicesAsync( new DescribeServicesRequest() { Language = "en" }); return response.HttpStatusCode == HttpStatusCode.OK; } catch (Amazon.AWSSupport.AmazonAWSSupportException ex) { if (ex.ErrorCode == "SubscriptionRequiredException") { return false; } else throw; } } }