# Java SDK The Sinch Java SDK allows you to quickly interact with the from inside your Java applications. When using the Java SDK, the code representing requests and queries sent to and responses received from the are structured similarly to those that are sent and received using the . Important Java SDK links: The following links are available for your reference: - [Sinch Java SDK repository](https://github.com/sinch/sinch-sdk-java) - [Sinch Java SDK releases](https://github.com/sinch/sinch-sdk-java/releases) - [Sinch Java SDK quickstart repository](https://github.com/sinch/sinch-sdk-java-quickstart) - [Sinch Java SDK snippets repository](https://github.com/sinch/sinch-sdk-java-snippets) - Generated [JavaDocs](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/) ## Client When using the Sinch Java SDK, you initialize communication with the Sinch backend by initializing the Java SDK's main client class. This client allows you to access the functionality of the Sinch Java SDK. ### Initialization Initialization of the Java SDK client class can be done in two ways, depending on which product you are using. #### Unified Project Authentication To successfully initialize the Sinch client class, you must provide a valid access key ID and access key secret combination. You must also provide your Project ID. For example: ```java package numbers.sdk; import com.sinch.sdk.SinchClient; public class App { public static String access_key = "YOUR_access_key"; public static String access_secret = "YOUR_access_secret"; public static String project_id = "YOUR_project_id" public static void main(String[] args) { SinchClient client = new SinchClient(Configuration.builder() .setKeyId(access_key) .setKeySecret(access_secret) .setProjectId(project_id) .build()); } ``` #### Application Authentication Voice API To start using the SDK, you need to initialize the main client class and create a configuration object to connect to your Sinch account and Voice app. You can find all of the credentials you need on your Sinch [dashboard](https://dashboard.sinch.com/voice/apps). ```java import com.sinch.sdk.SinchClient; import com.sinch.sdk.models.Configuration; public class App { public static void main(String[] args) { SinchClient client = new SinchClient(Configuration.builder() .setApplicationKey("YOUR_application_key") .setApplicationSecret("YOUR_application_secret") .build()); } } ``` Note For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials. Verification API To start using the SDK, you need to initialize the main client class and create a configuration object to connect to your Sinch account and Verification app. You can find all of the credentials you need on your Sinch [dashboard](https://dashboard.sinch.com/verification/apps). ```java import com.sinch.sdk.SinchClient; import com.sinch.sdk.models.Configuration; public class App { public static void main(String[] args) { SinchClient client = new SinchClient(Configuration.builder() .setApplicationKey("YOUR_application_key") .setApplicationSecret("YOUR_application_secret") .build()); } } ``` Note For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials. ## Domains The Java SDK currently supports the following products: Numbers SMS Conversation Voice Verification ### Numbers Domain Note: This guide describes the syntactical structure of the Java SDK for the Numbers API, including any differences that may exist between the API itself and the SDK. For a full reference on Numbers API calls and responses, see the [Numbers API Reference](/docs/numbers/api-reference/numbers). This code sample is an example of how to use the Java SDK to list the available numbers of a given type and region. We've also provided an example that accomplishes the same task using the REST API. SDK Snippet.java // This code returns a list of all the available numbers for a given set of search criteria. package numbers; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.NumberType; import com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberListRequest; import com.sinch.sdk.domains.numbers.models.v1.response.AvailableNumberListResponse; import java.util.logging.Logger; public class Snippet { private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); static void execute(NumbersService numbersService) { String regionCode = "US"; NumberType type = NumberType.LOCAL; AvailableNumberListRequest parameters = AvailableNumberListRequest.builder().setRegionCode(regionCode).setType(type).build(); LOGGER.info( String.format("Listing available number type '%s' for region '%s'", type, regionCode)); AvailableNumberListResponse response = numbersService.searchForAvailableNumbers(parameters); response .iterator() .forEachRemaining( number -> LOGGER.info(String.format("Available number details: %s", number))); } } REST API ```java import java.net.*; import java.net.http.*; import java.util.*; public class App { public static void main(String[] args) throws Exception { var httpClient = HttpClient.newBuilder().build(); var host = "https://numbers.api.sinch.com"; var projectId = "YOUR_projectId"; var pathname = "/v1/projects/" + projectId + "/availableNumbers"; var request = HttpRequest.newBuilder() .GET() .uri(URI.create(host + pathname )) .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("YOUR_username:YOUR_password").getBytes())) .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `client.numbers().v1().[endpoint_category()].[method()]`. In the Sinch Java SDK, Numbers API endpoints are accessible through the client: - `numbers().v1()` - `numbers().v1().regions()` - `numbers().v1().callbackConfiguration()` - `numbers().v1().webhooks()` For example: ```java var numbers = client.numbers().v1().list(AvailableNumberListRequest.builder() .setType(NumberType.LOCAL) .setRegionCode("US") .build()); ``` The field mappings are described in the sections below. The `numbers().v1()` category of the Java SDK has methods that correspond to the [available](/docs/numbers/api-reference/numbers/available-number/) and [active](/docs/numbers/api-reference/numbers/active-number/) endpoints. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [Activate a new phone number](/docs/numbers/api-reference/numbers/available-number/numberservice_rentnumber) | `rent()` | [rent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#rent(java.lang.String,com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberRentRequest)) | | [Search for available phone numbers](/docs/numbers/api-reference/numbers/available-number/numberservice_listavailablenumbers) | `searchForAvailableNumbers()` | [searchForAvailableNumbers](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#searchForAvailableNumbers(com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberListRequest)) | | [Check availability of a specific number](/docs/numbers/api-reference/numbers/available-number/numberservice_getavailablenumber) | `checkAvailability()` | [checkAvailability](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#checkAvailability(java.lang.String)) | | [Rent any available number](/docs/numbers/api-reference/numbers/available-number/numberservice_rentanynumber) | `rentAny()` | [rentAny](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#rentAny(com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberRentAnyRequest)) | | [List active numbers for a project](/docs/numbers/api-reference/numbers/active-number/numberservice_listactivenumbers) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#list(com.sinch.sdk.domains.numbers.models.v1.request.ActiveNumberListRequest)) | | [Update active number](/docs/numbers/api-reference/numbers/active-number/numberservice_updateactivenumber) | `update()` | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#update(java.lang.String,com.sinch.sdk.domains.numbers.models.v1.request.ActiveNumberUpdateRequest)) | | [Retrieve active number](/docs/numbers/api-reference/numbers/active-number/numberservice_getactivenumber) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#get(java.lang.String)) | | [Release active number](/docs/numbers/api-reference/numbers/active-number/numberservice_releasenumber) | `release()` | [release](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/NumbersService.html#release(java.lang.String)) | The `numbers().v1().regions()` category of the Java SDK corresponds to the [availableRegions](/docs/numbers/api-reference/numbers/available-regions/) endpoint. The mapping between the API operation and corresponding Java method are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [List available regions](/docs/numbers/api-reference/numbers/available-regions/) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/AvailableRegionService.html#list(com.sinch.sdk.domains.numbers.models.v1.regions.available.request.AvailableRegionListRequest)) | The `numbers().v1().callbackConfiguration()` category of the Java SDK corresponds to the [callbackConfiguration](/docs/numbers/api-reference/numbers/numbers-callbacks/) endpoint. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [Get callbacks configuration](/docs/numbers/api-reference/numbers/numbers-callbacks/getcallbackconfiguration) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/CallbackConfigurationService.html#get()) | | [Update callback configuration](/docs/numbers/api-reference/numbers/numbers-callbacks/updatecallbackconfiguration) | `update()` | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/CallbackConfigurationService.html#update(com.sinch.sdk.domains.numbers.models.v1.callbacks.request.CallbackConfigurationUpdateRequest)) | The `numbers().v1().webhooks()` category of the Java SDK corresponds to the [Event notification](/docs/numbers/api-reference/numbers/numbers-callbacks/importednumberservice_eventscallback) operation. The mapping between the API operation and corresponding Java method are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [Event notification](/docs/numbers/api-reference/numbers/numbers-callbacks/importednumberservice_eventscallback) | `parseEvent()` | [parseEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/api/v1/WebHooksService.html#parseEvent(java.lang.String)) | Requests and queries made using the Java SDK are similar to those made using the SMS API. Many of the fields are named and structured similarly. For example, consider the representations of an SMS API message type. One field is represented in JSON, and the other is using our Java SDK: SDK ```java NumberType.MOBILE ``` REST API ```JSON "type": "MOBILE" ``` Many fields in the Java SDK are rendered as enums in data models. When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Java SDK, we use Java data models instead of nested JSON objects. For example, consider the SMS configuration objects below. One is represented in JSON, the other as a Java object: ```Java AvailableNumberListRequest.builder() .setType(NumberType.LOCAL) .setRegionCode("US") .build() ``` ```JSON { "type": "LOCAL", "regionCode": "US" } ``` Note that in the Java SDK you would use a `builder()` method to construct the appropriate data model in the correct structure. Response fields match the API responses. They are delivered as Java objects. ### SMS Domain Note: This guide describes the syntactical structure of the Java SDK for the SMS API, including any differences that may exist between the API itself and the SDK. For a full reference on SMS API calls and responses, see the [SMS API Reference](/docs/sms/api-reference/). The code sample below is an example of how to use the Java SDK to send an SMS message. We've also provided an example that accomplishes the same task using the REST API. SDK App.java //Use this code to send an SMS message. package sms; import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.api.v1.SMSService; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.util.Collections; import java.util.logging.Logger; public class Snippet { private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); static void execute(SMSService smsService) { BatchesService batchesService = smsService.batches(); String from = "YOUR_sinch_phone_number"; String recipient = "YOUR_recipient_phone_number"; String body = "This is a test SMS message using the Sinch Java SDK."; LOGGER.info(String.format("Submitting batch to send SMS to '%s'", recipient)); BatchResponse value = batchesService.send( TextRequest.builder() .setTo(Collections.singletonList(recipient)) .setBody(body) .setFrom(from) .build()); LOGGER.info("Response: " + value); } } REST API ```java package send.sms; import java.net.*; import java.net.http.*; import java.util.*; public class App { public static void main(String[] args) throws Exception { var httpClient = HttpClient.newBuilder().build(); var payload = String.join("\n" , "{" , " \"from\": \"YOUR_Sinch_virtual_number\"," , " \"to\": [" , " \"YOUR_recipient_number\"" , " ]," , " \"body\": \"YOUR_message_body\"," , " \"delivery_report\": \"summary\"," , " \"type\": \"mt_text\"" , "}" ); var host = "https://"; var servicePlanId = "YOUR_service_plan_id_PARAMETER"; var region = "us"; var pathname = region + ".sms.api.sinch.com/xms/v1/" + servicePlanId + "/batches"; var request = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(payload)) .uri(URI.create(host + pathname )) .header("Content-Type", "application/json") .header("Authorization", "Bearer ") .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` Note that the REST API uses the Service Plan ID and and API token instead of Project ID and access keys. The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `client.sms.[endpoint_category()].[method()]`. In the Sinch Java SDK, SMS API endpoints are accessible through the client. The naming convention of the endpoints in the SDK resembles the API: - `groups()` - `batches()` - `inbounds()` - `deliveryReports()` For example: ```java var batches = client.sms().batches().list(BatchesListRequestParameters.builder() .setPage(1) .setPageSize(10) .setFrom("YOUR_from_number") .setStartDate("2023-11-01T00:00:00.00") .setEndDate("2023-11-30T00:00:00.00") .setClientReference("YOUR_reference") .build()); ``` The field mappings are described in the sections below. The `sms().batches()` category of the Java SDK corresponds to the [batches](/docs/sms/api-reference/sms/batches/) endpoint. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [Send](/docs/sms/api-reference/sms/batches/sendsms) | `send()` | [send](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#send(com.sinch.sdk.domains.sms.models.BaseBatch)) | | [List batches](docs/sms/api-reference/sms/batches/listbatches) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#list(com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters)) | | [Dry run](/docs/sms/api-reference/sms/batches/dry_run) | `dryRun()` | [dryRun](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#dryRun(boolean,int,com.sinch.sdk.domains.sms.models.BaseBatch)) | | [Get a batch message](/docs/sms/api-reference/sms/batches/getbatchmessage) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#get(java.lang.String)) | | [Update a batch message](/docs/sms/api-reference/sms/batches/updatebatchmessage) | `update()` | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#update(java.lang.String,com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest)) | | [Replace a batch](/docs/sms/api-reference/sms/batches/replacebatch) | `replace()` | [replace](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#replace(java.lang.String,com.sinch.sdk.domains.sms.models.BaseBatch)) | | [Cancel a batch message](/docs/sms/api-reference/sms/batches/cancelbatchmessage) | `cancel()` | [cancel](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#cancel(java.lang.String)) | | [Send delivery feedback for a message](/docs/sms/api-reference/sms/batches/deliveryfeedback) | `sendDeliveryFeedback()` | [sendDeliveryFeedback](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/batchesService.html#sendDeliveryFeedback(java.lang.String,java.util.Collection)) | The `sms().deliveryReports()` category of the Java SDK corresponds to the [delivery_report and delivery_reports](/docs/sms/api-reference/sms/delivery-reports/) endpoints. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [Retrieve a delivery report](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbybatchid) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/DeliveryReportsService.html#get(java.lang.String,com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters)) | | [Retrieve a recipient delivery report](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreportbyphonenumber) | `getForNumber()` | [getForNumber](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/DeliveryReportsService.html#getForNumber(java.lang.String,java.lang.String)) | | [Retrieve a list of delivery reports](/docs/sms/api-reference/sms/delivery-reports/getdeliveryreports) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/DeliveryReportsService.html#list(com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters)) | The `sms().groups()` category of the Java SDK corresponds to the [groups](/docs/sms/api-reference/sms/groups/) endpoint. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [List groups](/docs/sms/api-reference/sms/groups/listgroups) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#list()) | | [Create a group](/docs/sms/api-reference/sms/groups/creategroup) | `create()` | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#create(com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters)) | | [Retrieve a group](/docs/sms/api-reference/sms/groups/retrievegroup) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#get(java.lang.String)) | | [Update a group](/docs/sms/api-reference/sms/groups/updategroup) | `update()` | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#update(java.lang.String,com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters)) | | [Replace a group](/docs/sms/api-reference/sms/groups/replacegroup) | `replace()` | [replace](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#replace(java.lang.String,com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters)) | | [Delete a group](/docs/sms/api-reference/sms/groups/deletegroup) | `delete()` | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#delete(java.lang.String)) | | [List group member phone numbers](/docs/sms/api-reference/sms/groups/getmembers) | `listMembers()` | [listMembers](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/GroupsService.html#listMembers(java.lang.String)) | The `sms().inbounds()` category of the Java SDK corresponds to the [inbounds](/docs/sms/api-reference/sms/inbounds/) endpoint. The mapping between the API operations and corresponding Java methods are described below, as well as links to the JavaDocs page: | API operation | SDK method | JavaDocs | | --- | --- | --- | | [List incoming messages](/docs/sms/api-reference/sms/inbounds/listinboundmessages) | `list()` | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/InboundsService.html#get(java.lang.String)) | | [Retrieve inbound message](/docs/sms/api-reference/sms/inbounds/retrieveinboundmessage) | `get()` | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/sms/InboundsService.html#get(java.lang.String)) | Requests and queries made using the Java SDK are similar to those made using the SMS API. Many of the fields are named and structured similarly. For example, consider the representations of an SMS API message type. One field is represented in JSON, and the other is using our Java SDK: SDK ```java DeliveryReportType.FULL ``` REST API ```JSON "delivery_report": "full" ``` Many fields in the Java SDK are rendered as enums in data models. When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Java SDK, we use Java data models instead of nested JSON objects. For example, consider the SMS configuration objects below. One is represented in JSON, the other as a Java object: SDK ```Java SendSmsBatchTextRequest.builder() .setTo(Collections.singletonList("YOUR_recipient_phone_number")) .setBody("Test message using Java SDK") .setFrom("YOUR_sinch_phone_number") .setDeliveryReport(DeliveryReportType.NONE) .build() ``` REST API ```JSON { "from": "YOUR_Sinch_number", "to": [ "YOUR_number" ], "body": "Hello from Sinch!", "delivery_report": "none", "type": "mt_text" } ``` Note that in the Java SDK you would use a `builder()` method to construct the appropriate data model in the correct structure. Note also that while in the raw JSON request body you can specify the message type, the Java SDK has a specific Batch request object for each message type. Response fields match the API responses. They are delivered as Java objects. ### Conversation Domain Note: This guide describes the syntactical structure of the Java SDK for the Conversation API, including any differences that may exist between the API itself and the SDK. For a full reference on Conversation API calls and responses, see the [Conversation REST API Reference](/docs/conversation/api-reference/). The code sample below is an example of how to use the Java SDK to send a text message on the SMS channel of a Conversation API app. We've also provided an example that accomplishes the same task using the REST API. SDK send-message.js package conversation; import com.sinch.sdk.domains.conversation.api.v1.ConversationService; import com.sinch.sdk.domains.conversation.api.v1.MessagesService; import com.sinch.sdk.domains.conversation.models.v1.*; import com.sinch.sdk.domains.conversation.models.v1.messages.*; import com.sinch.sdk.domains.conversation.models.v1.messages.request.*; import com.sinch.sdk.domains.conversation.models.v1.messages.response.SendMessageResponse; import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.*; import java.util.*; import java.util.Collections; import java.util.logging.Logger; public class Snippet { private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); static void execute(ConversationService conversationService) { MessagesService messagesService = conversationService.messages(); String appId = "YOUR_app_id"; String from = "YOUR_sms_sender"; String to = "RECIPIENT_number"; String body = "This is a test Conversation message using the Sinch Java SDK."; String smsSender = "SMS_SENDER"; ChannelRecipientIdentities recipients = ChannelRecipientIdentities.of( ChannelRecipientIdentity.builder() .setChannel(ConversationChannel.SMS) .setIdentity(to) .build()); AppMessage message = AppMessage.builder() .setBody(TextMessage.builder().setText(body).build()) .build(); SendMessageRequest request = SendMessageRequest.builder() .setAppId(appId) .setRecipient(recipients) .setMessage(message) .setChannelProperties(Collections.singletonMap(smsSender, from)) .build(); LOGGER.info("Sending SMS Text using Conversation API"); SendMessageResponse value = messagesService.sendMessage(request); LOGGER.info("Response: " + value); } } REST API ```Java // Find your App ID at dashboard.sinch.com/convapi/apps // Find your Project ID at dashboard.sinch.com/settings/project-management // Get your Access Key and Access Secret at dashboard.sinch.com/settings/access-keys import java.net.*; import java.net.http.*; import java.util.*; public class App { public static void main(String[] args) throws Exception { var httpClient = HttpClient.newBuilder().build(); var payload = String.join("\n" , "{" , " \"app_id\": \"{APP_ID}\"," , " \"recipient\": {" , " \"identified_by\": {" , " \"channel_identities\": [" , " {" , " \"channel\": \"{CHANNEL}\"," , " \"identity\": \"{IDENTITY}\"" , " }" , " ]" , " }" , " }," , " \"message\": {" , " \"text_message\": {" , " \"text\": \"This is a text message.\"" , " }" , " }" , "}" ); var host = "https://{region}.conversation.api.sinch.com"; var projectId = "YOUR_project_id_PARAMETER"; var region = "us"; var pathname = "/v1/projects/%7Bproject_id%7D/messages:send"; var request = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(payload)) .uri(URI.create(host + pathname )) .header("Content-Type", "application/json") .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((":").getBytes())) .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `client.conversation().v1().[endpoint_category()].[method()]` or `client.conversation().templates().[templates_version()].[method()]`. In the Sinch Java SDK, Conversation API endpoints are accessible through the client (either a general client or a Conversation-specific client). The naming convention of the endpoint's representation in the SDK matches the API: - `v1().messages()` - `v1().app()` - `v1().contact()` - `v1().events()` - `v1().transcoding()` - `v1().capability()` - `templates.v1().templates()` - `templates.v2().templates()` - `v1().webhooks()` - `v1().conversation()` For example: ```Java SendMessageResponse response = client.conversation().v1().messages().sendMessage(SendMessageRequest.builder() .setAppId("YOUR_app_id") .setRecipient(ChannelRecipientIdentities.of(ChannelRecipientIdentity.builder().setChannel(ConversationChannel.SMS).setIdentity("RECIPIENT_number").build())) .setMessage(AppMessage.builder().setBody(TextMessage.builder().setText("This is a test Conversation message using the Sinch Java SDK.").build()).build()) .setChannelProperties(Collections.singletonMap("SMS_SENDER", "YOUR_sms_sender")) .build()); ``` The `messages` category of the Java SDK corresponds to the [messages](/docs/conversation/api-reference/conversation/messages/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Send a message](/docs/conversation/api-reference/conversation/messages/messages_sendmessage) | [sendMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)), or you could use any of the following message-specific methods: | | | [sendCardMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendCardMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendCarouselMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendCarouselMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendChoiceMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendChoiceMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendContactInfoMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendContactInfoMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendListMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendListMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendLocationMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendLocationMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendMediaMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendMediaMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendTemplateMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendTemplateMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | | [sendTextMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#sendTextMessage(com.sinch.sdk.domains.conversation.models.v1.messages.request.SendMessageRequest)) | | [Get a message](/docs/conversation/api-reference/conversation/messages/messages_getmessage) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#get(java.lang.String)) | | [Delete a message](/docs/conversation/api-reference/conversation/messages/messages_deletemessage) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#delete(java.lang.String)) | | [List messages](/docs/conversation/api-reference/conversation/messages/messages_listmessages) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#list(com.sinch.sdk.domains.conversation.models.v1.messages.request.MessagesListRequest)) | | [Update a message's metadata](/docs/conversation/api-reference/conversation/messages/messages_updatemessagemetadata) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/MessagesService.html#list(com.sinch.sdk.domains.conversation.models.v1.messages.request.MessagesListRequest)) | The `app` category of the Java SDK corresponds to the [apps](/docs/conversation/api-reference/conversation/app/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List all apps for a given project](/docs/conversation/api-reference/conversation/app/app_listapps) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/AppService.html#list()) | | [Create an app](/docs/conversation/api-reference/conversation/app/app_createapp) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/AppService.html#create(com.sinch.sdk.domains.conversation.models.v1.app.request.AppCreateRequest)) | | [Get an app](/docs/conversation/api-reference/conversation/app/app_getapp) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/AppService.html#get(java.lang.String)) | | [Delete an app](/docs/conversation/api-reference/conversation/app/app_deleteapp) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/AppService.html#delete(java.lang.String)) | | [Update an app](/docs/conversation/api-reference/conversation/app/app_updateapp) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/AppService.html#update(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.app.request.AppUpdateRequest)) | [This class](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/models/v1/credentials/ConversationChannelCredentialsBuilderFactory.html) will help you define channel credentials when creating or updating an app. Each channel is represented by a corresponding method, and invoking that method will allows you to more easily determine the information that is required to create the credentials. The `contact` category of the Java SDK corresponds to the [contacts](/docs/conversation/api-reference/conversation/contact/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List contacts](/docs/conversation/api-reference/conversation/contact/contact_listcontacts) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#list(com.sinch.sdk.domains.conversation.models.v1.contact.request.ContactListRequest)) | | [Create a contact](/docs/conversation/api-reference/conversation/contact/contact_createcontact) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#create(com.sinch.sdk.domains.conversation.models.v1.contact.request.ContactCreateRequest)) | | [Get a contact](/docs/conversation/api-reference/conversation/contact/contact_getcontact) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#get(java.lang.String)) | | [Delete a contact](/docs/conversation/api-reference/conversation/contact/contact_deletecontact) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#delete(java.lang.String)) | | [Update a contact](/docs/conversation/api-reference/conversation/contact/contact_updatecontact) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#update(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.contact.Contact)) | | [Merge two contacts](/docs/conversation/api-reference/conversation/contact/contact_mergecontact) | [mergeContact](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#mergeContact(java.lang.String,java.lang.String)) | | [Get channel profile](/docs/conversation/api-reference/conversation/contact/contact_getchannelprofile) | [getChannelProfileByContactId](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#getChannelProfileByContactId(com.sinch.sdk.domains.conversation.models.v1.contact.request.ContactGetChannelProfileByContactIdRequest)) or [getChannelProfileByChannelIdentity](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ContactService.html#getChannelProfileByChannelIdentity(com.sinch.sdk.domains.conversation.models.v1.contact.request.ContactGetChannelProfileByChannelIdentityRequest)) | The `conversations` category of the Java SDK corresponds to the [conversations](docs/conversation/api-reference/conversation/conversation/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List conversations](/docs/conversation/api-reference/conversation/conversation/conversation_listconversations) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#list(com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest)) | | [Create a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_createconversation) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#create(com.sinch.sdk.domains.conversation.models.v1.conversation.request.CreateConversationRequest)) | | [Get a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_getconversation) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#get(java.lang.String)) | | [Delete a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_deleteconversation) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#delete(java.lang.String)) | | [Update a conversation](/docs/conversation/api-reference/conversation/conversation/conversation_updateconversation) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#update(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy,com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation)) | | [Stop conversation](/docs/conversation/api-reference/conversation/conversation/conversation_stopactiveconversation) | [stopActive](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#stopActive(java.lang.String)) | | [Inject a message](/docs/conversation/api-reference/conversation/conversation/conversation_injectmessage) | [injectMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#injectMessage(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequest)) | | [Inject an event](/docs/conversation/api-reference/conversation/conversation/events_injectevent) | [injectEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#injectEvent(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectEventRequest)) | | [List recent conversations](/docs/conversation/api-reference/conversation/conversation/conversation_listrecentconversations) | [listRecent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.html#listRecent(com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest)) | The `events` category of the Java SDK corresponds to the [events](/docs/conversation/api-reference/conversation/events/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Send an event](/docs/conversation/api-reference/conversation/events/events_sendevent) | [send](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/EventsService.html#send(com.sinch.sdk.domains.conversation.models.v1.events.request.SendEventRequest)) | | [Get an event](/docs/conversation/api-reference/conversation/events/events_getevent) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/EventsService.html#get(java.lang.String)) | | [Delete an event](/docs/conversation/api-reference/conversation/events/events_deleteevents) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/EventsService.html#delete(java.lang.String)) | | [List events](/docs/conversation/api-reference/conversation/events/events_listevents) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/EventsService.html#list(com.sinch.sdk.domains.conversation.models.v1.events.request.EventsListRequest)) | The `transcoding` category of the Java SDK corresponds to the [messages:transcode](/docs/conversation/api-reference/conversation/transcoding/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Transcode a message](/docs/conversation/api-reference/conversation/transcoding/transcoding_transcodemessage) | [transcodeMessage](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/TranscodingService.html#transcodeMessage(com.sinch.sdk.domains.conversation.models.v1.transcoding.request.TranscodeMessageRequest)) | The `capability` category of the Java SDK corresponds to the [capability](/docs/conversation/api-reference/conversation/capability/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [Capability lookup](/docs/conversation/api-reference/conversation/capability/capability_querycapability) | [lookup](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/CapabilityService.html#lookup(com.sinch.sdk.domains.conversation.models.v1.capability.request.QueryCapabilityRequest)) | The `webhooks` category of the Java SDK corresponds to the [webhooks](/docs/conversation/api-reference/conversation/webhooks/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List webhooks](/docs/conversation/api-reference/conversation/webhooks/webhooks_listwebhooks) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#list(java.lang.String)) | | [Create a new webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_createwebhook) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#create(com.sinch.sdk.domains.conversation.models.v1.webhooks.Webhook)) | | [Get a webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_getwebhook) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#get(java.lang.String)) | | [Update an existing webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_updatewebhook) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#update(java.lang.String,com.sinch.sdk.domains.conversation.models.v1.webhooks.Webhook)) | | [Delete an existing webhook](/docs/conversation/api-reference/conversation/webhooks/webhooks_deletewebhook) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#delete(java.lang.String)) | | No corresponding operation. You can use this function to authenticate information received from payloads. This function takes the `secret` parameter, which is the Secret token to be used to validate the received request. | [validateAuthenticationHeader](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#validateAuthenticationHeader(java.lang.String,java.util.Map,java.lang.String)) | | No corresponding operation. You can use this function to deserialize payloads received from callbacks. This function takes the `jsonPayload` parameter, which is the received payload. | [parseEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/v1/WebHooksService.html#parseEvent(java.lang.String)) | The `templates` (version 1) category of the Java SDK corresponds to the [Templates](/docs/conversation/api-reference/template/templates-v1/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List all templates belonging to a project ID](/docs/conversation/api-reference/template/templates-v1/templates_listtemplates) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.html#list()) | | [Creates a template](/docs/conversation/api-reference/template/templates-v1/templates_createtemplate) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.html#create(com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1)) | | [Updates a template](/docs/conversation/api-reference/template/templates-v1/templates_updatetemplate) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.html#update(java.lang.String,com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1)) | | [Get a template](/docs/conversation/api-reference/template/templates-v1/templates_gettemplate) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.html#get(java.lang.String)) | | [Delete a template](/docs/conversation/api-reference/template/templates-v1/templates_deletetemplate) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.html#delete(java.lang.String)) | The `templates` (version 2) category of the Java SDK corresponds to the [Templates-V2](/docs/conversation/api-reference/template/templates-v2/) endpoint. The mapping between the API operations and corresponding methods are described below: | API operation | SDK method | | --- | --- | | [List all templates belonging to a project ID](/docs/conversation/api-reference/template/templates-v2/templates_v2_listtemplates) | [list](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#list()) | | [Creates a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_createtemplate) | [create](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#create(com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2)) | | [Lists translations for a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_deletetemplate) | [listTranslations](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#listTranslations(java.lang.String,com.sinch.sdk.domains.conversation.templates.models.v2.request.TranslationListRequest)) | | [Updates a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_updatetemplate) | [update](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#update(java.lang.String,com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2)) | | [Get a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_gettemplate) | [get](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#get(java.lang.String)) | | [Delete a template](/docs/conversation/api-reference/template/templates-v2/templates_v2_deletetemplate) | [delete](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.html#delete(java.lang.String)) | Requests and queries made using the Java SDK are similar to those made using the Conversation API. Many of the fields are named and structured similarly. For example, consider the representation of a Conversation API channel. One field is represented in our Java SDK, and the other is using the REST API: SDK ```Java ConversationChannel.SMS ``` REST API ```Java " \"channel\": \"SMS\"," ``` Note that the fields have similar names, and many fields in the Java SDK are rendered as enums in data models. Additionally, path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding method. For example, consider this example in which the `get` method of `messages` is invoked: SDK ```Java var response = client.conversation().v1().messages().get("YOUR_message_id", "CONVERSATION_SOURCE"); ``` REST API ```Java var host = "https://{region}.conversation.api.sinch.com"; var projectId = "YOUR_project_id_PARAMETER"; var messageId = "YOUR_message_id_PARAMETER"; var region = "us"; var pathname = "/v1/projects/%7Bproject_id%7D/messages/%7Bmessage_id%7D"; var request = HttpRequest.newBuilder() .GET() .uri(URI.create(host + pathname )) .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((":").getBytes())) .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); ``` When using the Conversation API, `message_id` would be included as a path parameter, and `messages_source` would be included as a query parameter in the JSON payload. With the Java SDK, both parameters are included as arguments in the `get` method. Response fields match the API responses. They are delivered as Java objects. ### Voice Domain Note This guide describes the syntactical structure of the Java SDK for the Voice API, including any differences that may exist between the API itself and the SDK. For a full reference on Voice API calls and responses, see the [Voice API Reference](/docs/voice/api-reference/voice). The code sample below is an example of how to use the Java SDK to make a text to speech phone call to phone number using the Java SDK and the Voice API. We've also provided an example that accomplishes the same task using the REST API. SDK Snippet.java package voice; import com.sinch.sdk.domains.voice.api.v1.CalloutsService; import com.sinch.sdk.domains.voice.api.v1.VoiceService; import com.sinch.sdk.domains.voice.models.v1.callouts.request.CalloutRequestTTS; import com.sinch.sdk.domains.voice.models.v1.destination.DestinationPstn; import java.util.logging.Logger; public class Snippet { private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); public static String execute(VoiceService voiceService) { CalloutsService calloutsService = voiceService.callouts(); String phoneNumber = "YOUR_phone_number"; String message = "Hello, this is a call from Sinch. Congratulations! You made your first call."; LOGGER.info("Calling '" + phoneNumber + '"'); CalloutRequestTTS parameters = CalloutRequestTTS.builder() .setDestination(DestinationPstn.from(phoneNumber)) .setText(message) .build(); String callId = calloutsService.textToSpeech(parameters); LOGGER.info("Call started with id: '" + callId + '"'); return callId; } } REST API App.java package app; import java.net.*; import java.net.http.*; import java.util.*; public class App { private static final String key = ""; private static final String secret = ""; private static final String fromNumber = ""; private static final String to = ""; private static final String locale = ""; public static void main(String[] args) throws Exception { var httpClient = HttpClient.newBuilder().build(); var payload = String.join("\n" , "{" , " \"method\": \"ttsCallout\"," , " \"ttsCallout\": {" , " \"cli\": \"" + fromNumber + "\"," , " \"destination\": {" , " \"type\": \"number\"," , " \"endpoint\": \"" + to + "\"" , " }," , " \"locale\": \"" + locale + "\"," , " \"text\": \"Hello, this is a call from Sinch. Congratulations! You made your first call.\"" , " }" , "}" ); var host = "https://calling.api.sinch.com"; var pathname = "/calling/v1/callouts"; var request = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(payload)) .uri(URI.create(host + pathname )) .header("Content-Type", "application/json") .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((key + ":" + secret).getBytes())) .build(); var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `client.voice().[endpoint_category()].[method()]`. In the Sinch Java SDK, Voice API endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API: - `voice().callouts()` - `voice().calls()` - `voice().conferences()` - `voice().applications()` For example: ```java var response = client.voice() .callouts() .textToSpeech(CalloutRequestParametersTTS .builder() .setDestination(DestinationNumber.valueOf("YOUR_phone_number")) .setText("Thank you for calling Sinch. This call will now end.") .build()); ``` The `voice().callouts()` category of the Java SDK corresponds corresponds to the [callouts](/docs/voice/api-reference/voice/callouts/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Makes a Text-to-speech callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `textToSpeech()` | [textToSpeech](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CalloutsService.html#textToSpeech(com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersTTS)) | | [Makes a Conference callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `conference()` | [conference](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CalloutsService.html#conference(com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersConference)) | | [Makes a Custom callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/request) | `Custom()` | [custom](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CalloutsService.html#custom(com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersCustom)) | The `voice().calls()` category of the Java SDK corresponds corresponds to the [calls](/docs/voice/api-reference/voice/calls/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Get information about a call](/docs/voice/api-reference/voice/calls/calling_getcallresult) | `get()` | [get](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CallsService.html#get(java.lang.String)) | | [Manage call with `callLeg`](/docs/voice/api-reference/voice/calls/calling_managecallwithcallleg) | `manageWithCallLeg()` | [manageWithCallLeg](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CallsService.html#manageWithCallLeg(java.lang.String,com.sinch.sdk.domains.voice.models.CallLegType,com.sinch.sdk.domains.voice.models.svaml.SVAMLControl)) | | [Updates a call in progress](/docs/voice/api-reference/voice/calls/calling_updatecall) | `update()` | [update](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/CallsService.html#update(java.lang.String,com.sinch.sdk.domains.voice.models.svaml.SVAMLControl)) | The `voice().conferences()` category of the Java SDK corresponds corresponds to the [conferences](/docs/voice/api-reference/voice/conferences/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Makes a conference callout](/docs/voice/api-reference/voice/callouts/callouts#callouts/callouts/t=request&path=&d=0/conferencecallout) | `call()` | [call](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ConferencesService.html#call(com.sinch.sdk.domains.voice.models.requests.CalloutRequestParametersConference)) | | [Get information about a conference](/docs/voice/api-reference/voice/conferences/calling_getconferenceinfo) | `get()` | [get](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ConferencesService.html#get(java.lang.String)) | | [Manage a conference participant](/docs/voice/api-reference/voice/conferences/calling_manageconferenceparticipant) | `manageParticipant()` | [manageParticipant](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ConferencesService.html#manageParticipant(java.lang.String,java.lang.String,com.sinch.sdk.domains.voice.models.requests.ConferenceManageParticipantRequestParameters)) | | [Remove a participant from a conference](/docs/voice/api-reference/voice/conferences/calling_kickconferenceparticipant) | `kickParticipant()` | [kickParticipant](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ConferencesService.html#kickParticipant(java.lang.String,java.lang.String)) | | [Remove all participants from a conference](/docs/voice/api-reference/voice/conferences/calling_kickconferenceall) | `kickAll()` | [kickAll](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ConferencesService.html#kickAll(java.lang.String)) | The `voice().applications()` category of the Java SDK corresponds corresponds to the [configuration](/docs/voice/api-reference/voice/applications/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Return all the numbers assigned to an application](/docs/voice/api-reference/voice/applications/configuration_getnumbers) | `listNumbers()` | [listNumbers](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#listNumbers()) | | [Assign a number or list of numbers to an application](/docs/voice/api-reference/voice/applications/configuration_updatenumbers) | `assignNumbers()` | [assignNumbers](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#assignNumbers(com.sinch.sdk.domains.voice.models.requests.ApplicationsAssignNumbersRequestParameters)) | | [Unassign a number from an application](/docs/voice/api-reference/voice/applications/configuration_unassignnumber) | `unassignNumber()` | [unassignNumber](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#unassignNumber(com.sinch.sdk.models.E164PhoneNumber,java.lang.String)) | | [Return the callback URLs for an application](/docs/voice/api-reference/voice/applications/configuration_getcallbackurls) | `getCallbackUrls()` | [getCallbackUrls](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#getCallbackUrls(java.lang.String)) | | [Update the callback URL for an application](/docs/voice/api-reference/voice/applications/configuration_updatecallbackurls) | `updateCallbackUrls()` | [updateCallbackUrls](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#updateCallbackUrls(java.lang.String,com.sinch.sdk.domains.voice.models.CallbackUrls)) | | [Returns information about a number](/docs/voice/api-reference/voice/applications/calling_querynumber) | `queryNumber()` | [queryNumber](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/ApplicationsService.html#queryNumber(com.sinch.sdk.models.E164PhoneNumber)) | The `voice().webhooks()` category of the Java SDK are helper methods designed to assist in serializing/deserializing requests from and responses to the Sinch servers, as well as validate that the requests coming from the Sinch servers are authentic. | SDK method | Description | JavaDocs entry | | --- | --- | --- | | `validateAuthenticatedRequest()` | Validates if the request is authentic. It is a best practice to evaluate if a request is authentic before performing any business logic on it. | [validateAuthenticatedRequest](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/WebHooksService.html#validateAuthenticatedRequest(java.lang.String,java.lang.String,java.util.Map,java.lang.String)) | | `serializeVerificationResponse()` | Serializes a SVAMLControl response into a JSON string. You must serialize the response before returning it because the Sinch servers expect a JSON response. | [serializeWebhooksResponse](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/WebHooksService.html#serializeWebhooksResponse(com.sinch.sdk.domains.voice.models.svaml.SVAMLControl)) | | `unserializeVerificationEvent()` | Deserializes a JSON response into a Voice event class. You can use this method to handle different event types and write logic for different events. | [unserializeWebhooksEvent](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/WebHooksService.html#unserializeWebhooksEvent(java.lang.String)) | Requests and queries made using the Java SDK are similar to those made using the Voice API. Many of the fields are named and structured similarly. Many fields in the Java SDK are rendered as enums in data models. When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Java SDK, we use Java data models instead of nested JSON objects. For example, consider the Voice configuration objects below. One is represented in JSON, the other as a Java object: SDK ```Java CalloutRequestParametersTTS.builder() .setDestination(DestinationNumber.valueOf("YOUR_phone_number")) .setText("Thank you for calling Sinch. This call will now end.") .build() ``` JSON ```JSON { "method": "ttsCallout", "ttsCallout": { "destination": { "type": "number", "endpoint": "YOUR_phone_number" }, "text": "Thank you for calling Sinch. This call will now end." } } ``` Note that in the Java SDK you would use a specific helper class for the type of Voice call you want to make and a `builder()` method to construct the appropriate data model in the correct structure. Response fields match the API responses. They are delivered as Java objects. ### Verification Domain Note: This guide describes the syntactical structure of the Java SDK for the Verification API, including any differences that may exist between the API itself and the SDK. For a full reference on Verification API calls and responses, see the [Verification API Reference](/docs/verification/api-reference/verification). The code sample below is an example of how to use the Java SDK to initiate an SMS PIN Verification. We've also provided an example that accomplishes the same task using the REST API. SDK VerificationsSample.js package verification; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.utils.StringUtil; import com.sinch.sdk.domains.verification.api.v1.*; import com.sinch.sdk.domains.verification.models.v1.NumberIdentity; import com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms; import com.sinch.sdk.domains.verification.models.v1.report.response.VerificationReportResponseSms; import com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms; import com.sinch.sdk.domains.verification.models.v1.start.response.VerificationStartResponseSms; import com.sinch.sdk.models.E164PhoneNumber; import java.util.Scanner; public class VerificationsSample { private final VerificationService verificationService; public VerificationsSample(VerificationService verificationService) { this.verificationService = verificationService; } public void start() { E164PhoneNumber e164Number = promptPhoneNumber(); try { // Starting verification onto phone number String id = startSmsVerification(verificationService.verificationStart(), e164Number); // Ask user for received code Integer code = promptSmsCode(); // Submit the verification report reportSmsVerification(verificationService.verificationReport(), code, id); } catch (ApiException e) { echo("Error (%d): %s", e.getCode(), e.getMessage()); } } /** * Will start an SMS verification onto specified phone number * * @param service Verification Start service * @param phoneNumber Destination phone number * @return Verification ID */ private String startSmsVerification( VerificationStartService service, E164PhoneNumber phoneNumber) { echo("Sending verification request onto '%s'", phoneNumber.stringValue()); VerificationStartRequestSms parameters = VerificationStartRequestSms.builder() .setIdentity(NumberIdentity.valueOf(phoneNumber)) .build(); VerificationStartResponseSms response = service.startSms(parameters); echo("Verification started with ID '%s'", response.getId()); return response.getId(); } /** * Will use Sinch product to retrieve verification report by ID * * @param service Verification service * @param code Code received by SMS * @param id Verification ID related to the verification */ private void reportSmsVerification(VerificationReportService service, Integer code, String id) { VerificationReportRequestSms parameters = VerificationReportRequestSms.builder().setCode(String.valueOf(code)).build(); echo("Requesting report for '%s'", id); VerificationReportResponseSms response = service.reportSmsById(id, parameters); echo("Report response: %s", response); } /** * Prompt user for a valid phone number * * @return Phone number value */ private E164PhoneNumber promptPhoneNumber() { String input; boolean valid; do { input = prompt("\nEnter a phone number to start verification"); valid = E164PhoneNumber.validate(input); if (!valid) { echo("Invalid number '%s'", input); } } while (!valid); return E164PhoneNumber.valueOf(input); } /** * Prompt user for a SMS code * * @return Value entered by user */ private Integer promptSmsCode() { Integer code = null; do { String input = prompt("Enter the verification code to report the verification"); try { code = Integer.valueOf(input); } catch (NumberFormatException nfe) { echo("Invalid value '%s' (code should be numeric)", input); } } while (null == code); return code; } /** * Endless loop for user input until a valid string is entered or 'Q' to quit * * @param prompt Prompt to be used task user a value * @return The entered text from user */ private String prompt(String prompt) { String input = null; Scanner scanner = new Scanner(System.in); while (StringUtil.isEmpty(input)) { System.out.println(prompt + " ([Q] to quit): "); input = scanner.nextLine(); } if ("Q".equalsIgnoreCase(input)) { System.out.println("Quit application"); System.exit(0); } return input.trim(); } private void echo(String text, Object... args) { System.out.println(" " + String.format(text, args)); } } REST API ```java package app; import java.io.IOException; import java.net.*; import java.net.http.*; import java.util.*; public class App { private static final String applicationKey = ""; private static final String applicationSecret = ""; private static final String toNumber = ""; private static final String SINCH_URL = "https://verification.api.sinch.com/verification/v1/verifications"; public static final String JSON_CONTENT_TYPE = "application/json; charset=utf-8"; public static void main(String[] args) throws Exception { HttpResponse response = sendSMSPinWithBasicAuth(); System.out.println(response.body()); } private static HttpResponse sendSMSPinWithBasicAuth() throws IOException, InterruptedException { var httpClient = HttpClient.newBuilder().build(); var payload = getSMSVerificationRequestBody(); var request = HttpRequest.newBuilder() .POST(HttpRequest.BodyPublishers.ofString(payload)) .uri(URI.create(SINCH_URL)) .header("Content-Type", JSON_CONTENT_TYPE) .header("Authorization", "Basic " + Base64.getEncoder().encodeToString((applicationKey + ":" + applicationSecret).getBytes())) .build(); return httpClient.send(request, HttpResponse.BodyHandlers.ofString()); } private static String getSMSVerificationRequestBody() { return """ { "identity": { "type": "number", "endpoint": "%s" }, "method": "sms" } """.formatted(toNumber); } } ``` The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, `client.verification().v1().[endpoint_category()].[method()]`. In the Sinch Java SDK, Verification API endpoints are accessible through the client. The naming convention of the endpoints represented in the SDK matches the API: - `verification().v1().verificationStart()` - `verification().v1().verificationReport()` - `verification().v1().verificationStatus()` - `verification().v1().webhooks()` For example: ```java var identity = NumberIdentity.valueOf("YOUR_phone_number"); var response = client.verification().v1().verificationStart().startSms(VerificationStartRequestSms .builder() .setIdentity(identity) .build()); ``` The field mappings are described in the sections below. The `verification().v1().verificationStart()` category of the Java SDK corresponds to the [verifications](/docs/verification/api-reference/verification/verifications-start/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Start an SMS PIN verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `startSms()` | [startSms](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.html#startSms(com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestSms)) | | [Start a Flash Call verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `startFlashCall()` | [startFlashCall](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.html#startFlashCall(com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestFlashCall)) | | [Start a Phone Call verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `startPhoneCall()` | [startPhoneCall](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.html#startPhoneCall(com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestPhoneCall)) | | [Start a Data verification request](/docs/verification/api-reference/verification/verifications-start/startverification) | `startData()` | [startData](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStartService.html#startData(com.sinch.sdk.domains.verification.models.v1.start.request.VerificationStartRequestData)) | The `verification().v1().verificationReport()` category of the Java SDK corresponds to the [verifications](/docs/verification/api-reference/verification/verifications-report/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Report an SMS PIN verification code by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `reportSmsByIdentity()` | [reportSmsByIdentity](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportSmsByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms)) | | [Report an SMS PIN verification code by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `reportSmsById()` | [reportSmsById](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportSmsById(java.lang.String,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestSms)) | | [Report a Phone Call verification code by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `reportPhoneCallByIdentity()` | [reportPhoneCallByIdentity](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportPhoneCallByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall)) | | [Report a Phone Call verification code by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `reportPhoneCallById()` | [reportPhoneCallById](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportPhoneCallById(java.lang.String,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestPhoneCall)) | | [Report a FlashCall verification code by the identity of the recipient](/docs/verification/api-reference/verification/verifications-report/reportverificationbyidentity) | `reportFlashCallByIdentity()` | [reportFlashCallByIdentity](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportFlashCallByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall)) | | [Report a FlashCall verification code by the ID of the verification request](/docs/verification/api-reference/verification/verifications-report/reportverificationbyid) | `reportFlashCallById()` | [reportFlashCallById](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationReportService.html#reportFlashCallById(java.lang.String,com.sinch.sdk.domains.verification.models.v1.report.request.VerificationReportRequestFlashCall)) | The `verification().v1().verificationStatus()` category of the Java SDK corresponds to the [verifications](/docs/verification/api-reference/verification/verification-status/) endpoint. The mapping between the API operations and corresponding Java methods are described below: | API operation | SDK method | JavaDocs entry | | --- | --- | --- | | [Get the status of a verification by the ID of the verification request](/docs/verification/api-reference/verification/verification-status/verificationstatusbyid) | `getById()` | [getById](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.html#getById(java.lang.String)) | | [Get the status of a verification by the identity of the recipient](/docs/verification/api-reference/verification/verification-status/verificationstatusbyidentity) | `getByIdentity()` | [getByIdentity](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.html#getByIdentity(com.sinch.sdk.domains.verification.models.v1.NumberIdentity,com.sinch.sdk.domains.verification.models.v1.VerificationMethod)) | | [Get the status of a verification by a reference value](/docs/verification/api-reference/verification/verification-status/verificationstatusbyreference) | `getByReference()` | [getByReference](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/VerificationStatusService.html#getByReference(java.lang.String)) | The `verification().v1().webhooks()` category of the Java SDK corresponds to the [callbacks](/docs/verification/api-reference/verification/verification-callbacks/) section. The mapping between the API operations and corresponding Java methods are described below: | API callback | SDK method | JavaDocs entry | | --- | --- | --- | | [Validates if the authentication of the verification request matches](/docs/verification/api-reference/verification/verification-callbacks/verificationrequestevent) | `validateAuthenticatedRequest()` | [validateAuthenticationHeader](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/WebHooksService.html#validateAuthenticationHeader(java.lang.String,java.lang.String,java.util.Map,java.lang.String)) | | [Serializes a verification response into a JSON string](/docs/verification/api-reference/verification/verification-callbacks/verificationrequestevent) | `serializeResponse()` | [serializeResponse](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/WebHooksService.html#serializeResponse(com.sinch.sdk.domains.verification.models.v1.webhooks.VerificationRequestEventResponse)) | | [Deserializes a JSON response into the corresponding Verification event class](/docs/verification/api-reference/verification/verification-callbacks/verificationrequestevent) | `parseEvent()` | [parseEvent](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/verification/api/v1/WebHooksService.html#parseEvent(java.lang.String)) | Requests and queries made using the Java SDK are similar to those made using the SMS API. Many of the fields are named and structured similarly. For example, consider the representations of a Verification method type. One field is represented in JSON, and the other is using our Java SDK: SDK ```java VerificationStartRequestSms ``` REST API ```JSON "method": "sms" ``` Many fields in the Java SDK are rendered as enums in data models. When making calls directly to the API, we use JSON objects, including (in some cases) nested JSON objects. When using the Java SDK, we use Java data models instead of nested JSON objects. For example, consider the Verification configuration objects below. One is represented in JSON, the other as a Java object: ```Java VerificationStartRequestSms.builder() .setIdentity(NumberIdentity.builder() .setEndpoint("YOUR_phone_number") .build()) .build() ``` ```JSON { "method": "sms", "identity": { "type": "number", "endpoint": "YOUR_phone_number" } } ``` Note that in the Java SDK you would use a specific helper class for the type of Verification you want to send and a `builder()` method to construct the appropriate data model in the correct structure. Response fields match the API responses. They are delivered as Java objects.