Use AddCommunicationToCase with an AWS SDK or command line tool - AWS Support

Use AddCommunicationToCase with an AWS SDK or command line tool

The following code examples show how to use AddCommunicationToCase.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <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; }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static void addAttachSupportCase(SupportClient supportClient, String caseId, String attachmentSetId) { try { AddCommunicationToCaseRequest caseRequest = AddCommunicationToCaseRequest.builder() .caseId(caseId) .attachmentSetId(attachmentSetId) .communicationBody("Please refer to attachment for details.") .build(); AddCommunicationToCaseResponse response = supportClient.addCommunicationToCase(caseRequest); if (response.result()) System.out.println("You have successfully added a communication to an AWS Support case"); else System.out.println("There was an error adding the communication to an AWS Support case"); } catch (SupportException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
JavaScript
SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import { AddCommunicationToCaseCommand } from "@aws-sdk/client-support"; import { client } from "../libs/client.js"; export const main = async () => { let attachmentSetId; try { // Add a communication to a case. const response = await client.send( new AddCommunicationToCaseCommand({ communicationBody: "Adding an attachment.", // Set value to an existing support case id. caseId: "CASE_ID", // Optional. Set value to an existing attachment set id to add attachments to the case. attachmentSetId, }), ); console.log(response); return response; } catch (err) { console.error(err); } };
Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun addAttachSupportCase(caseIdVal: String?, attachmentSetIdVal: String?) { val caseRequest = AddCommunicationToCaseRequest { caseId = caseIdVal attachmentSetId = attachmentSetIdVal communicationBody = "Please refer to attachment for details." } SupportClient { region = "us-west-2" }.use { supportClient -> val response = supportClient.addCommunicationToCase(caseRequest) if (response.result) { println("You have successfully added a communication to an AWS Support case") } else { println("There was an error adding the communication to an AWS Support case") } } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class SupportWrapper: """Encapsulates Support actions.""" def __init__(self, support_client): """ :param support_client: A Boto3 Support client. """ self.support_client = support_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ support_client = boto3.client("support") return cls(support_client) def add_communication_to_case(self, attachment_set_id, case_id): """ Add a communication and an attachment set to a case. :param attachment_set_id: The ID of an existing attachment set. :param case_id: The ID of the case. """ try: self.support_client.add_communication_to_case( caseId=case_id, communicationBody="This is an example communication added to a support case.", attachmentSetId=attachment_set_id, ) except ClientError as err: if err.response["Error"]["Code"] == "SubscriptionRequiredException": logger.info( "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." ) else: logger.error( "Couldn't add communication. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise

For a complete list of AWS SDK developer guides and code examples, see Using AWS Support with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.