{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/voice-2.0/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial"]},"product":"Voice v2 (preview)","type":"markdown"},"seo":{"title":"Java SDK Reference | Voice API v2 | Sinch","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Voice API v2","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice-2.0/**/*.md","docs/voice-2.0/**/*.yaml"],"excludeFiles":["docs/voice-2.0/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]},{"title":"Number Lookup API","description":"The Number Lookup API is designed to provide in-depth information about phone numbers, helping enterprises enhance their communication strategies and prevent fraud. By identifying the type of phone line (for example, mobile, landline, VoIP) and the associated carrier, the API allows businesses to optimize routing, reduce unnecessary costs, and improve customer engagement.","includeFiles":["docs/number-lookup-api-v2/**/*.md","docs/number-lookup-api-v2/**/*.yaml"],"excludeFiles":["docs/number-lookup-api-v2/index.md"]},{"title":"Functions","description":"Serverless compute for voice and messaging. Deploy your code and Sinch routes live calls and messages to it — no infrastructure to run.","includeFiles":["docs/functions/functions/**/*.md","docs/functions/concepts/**/*.md","docs/functions/reference/**/*.md"],"excludeFiles":["docs/functions/functions/index.md"]},{"title":"CLI","description":"One command line for every Sinch API and the full Functions lifecycle — scaffold, run locally, deploy, and manage.","includeFiles":["docs/functions/cli/**/*.md"],"excludeFiles":["docs/functions/cli/index.md"]}]},"description":"Learn the syntax of the Sinch Java SDK for Voice API v2."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"sinch-java-sdk-for-voice-api-v2","__idx":0},"children":["Sinch Java SDK for Voice API v2"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Java SDK allows you to quickly interact with the ","Voice API v2"," from inside your Java applications. When using the Java SDK, the code representing requests and queries sent to and responses received from the ","Voice API v2"," are structured similarly to those that are sent and received using the ","Voice API v2","."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The fastest way to get started with the SDK is to check out our ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/voice-2.0/getting-started"},"children":["getting-started"]}," guides. There you'll find all the instructions necessary to download, install, set up, and start using the SDK."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"syntax","__idx":1},"children":["Syntax"]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Note:"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide describes the syntactical structure of the Java SDK for the Voice API v2, including any differences that may exist between the API itself and the SDK. For a full reference on Voice API v2 calls and responses, see the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/voice-2.0/api-reference/voice"},"children":["Voice API v2 Reference"]},"."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The code sample below is an example of how to use the Java SDK to make a Text to speech phone call. We've also provided an example that accomplishes the same task using the REST API."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"SDK","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/code-snippets/java-sdk/voice/v2/make-call.sample.java","language":"java","title":"Start.java","header":{"title":"Start.java","controls":{"copy":{}}},"lang":"java","source":"/**\n * Sinch Java Snippet\n *\n * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java\n *\n * <p>See https://github.com/sinch/sinch-sdk-java/blob/main/examples/snippets/README.md for details\n */\npackage voice.v2.calls;\n\nimport com.sinch.sdk.SinchClient;\nimport com.sinch.sdk.domains.voice.api.v2.CallsService;\nimport com.sinch.sdk.domains.voice.models.v2.calls.request.StartCallRequest;\nimport com.sinch.sdk.domains.voice.models.v2.calls.response.StartCallResponse;\nimport com.sinch.sdk.domains.voice.models.v2.destination.Phone;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.calls.CallEvents;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.calls.DialCommand;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.calls.HangupCommand;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.playback.MessageEvents;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.playback.MessagesCommand;\nimport com.sinch.sdk.domains.voice.models.v2.svaml.playback.SayMessage;\nimport com.sinch.sdk.models.Configuration;\nimport java.util.Collections;\nimport java.util.logging.Logger;\nimport utils.Settings;\n\npublic class Start {\n\n  private static final Logger LOGGER = Logger.getLogger(Start.class.getName());\n\n  public static void main(String[] args) {\n\n    String projectId = Settings.getProjectId().orElse(\"MY_PROJECT_ID\");\n    String keyId = Settings.getKeyId().orElse(\"MY_KEY_ID\");\n    String keySecret = Settings.getKeySecret().orElse(\"MY_KEY_SECRET\");\n\n    // The phone number to be used as the caller ID, in E.164 format (e.g., +12025550123)\n    String sinchPhoneNumber = Settings.getPhoneNumber().orElse(\"MY_SINCH_PHONE_NUMBER\");\n    // The phone number you want to call, in E.164 format (e.g., +12025550123)\n    String recipientPhoneNumber = \"RECIPIENT_PHONE_NUMBER\";\n\n    Configuration configuration =\n        Configuration.builder()\n            .setProjectId(projectId)\n            .setKeyId(keyId)\n            .setKeySecret(keySecret)\n            .build();\n\n    SinchClient client = new SinchClient(configuration);\n\n    CallsService callsService = client.voice().v2().calls();\n\n    // Played to the recipient once the call is answered, then the call is hung up\n    MessagesCommand greeting =\n        MessagesCommand.builder()\n            .setMessages(\n                Collections.singletonList(\n                    SayMessage.builder()\n                        .setText(\"Hello, your call is now connected.\")\n                        .setVoiceName(\"Emma\")\n                        .build()))\n            .setEvents(\n                MessageEvents.builder()\n                    .setOnFinish(Collections.singletonList(HangupCommand.HANGUP_COMMAND))\n                    .build())\n            .build();\n\n    DialCommand dial =\n        DialCommand.builder()\n            .setCallName(\"Java_SDK_Snippet_Call\")\n            .setFrom(Phone.builder().setNumber(sinchPhoneNumber).build())\n            .setTo(Phone.builder().setNumber(recipientPhoneNumber).build())\n            .setEvents(\n                CallEvents.builder().setOnAnswer(Collections.singletonList(greeting)).build())\n            .build();\n\n    StartCallRequest request =\n        StartCallRequest.builder().setCommands(Collections.singletonList(dial)).build();\n\n    LOGGER.info(\"Start a call to: \" + recipientPhoneNumber);\n\n    StartCallResponse response = callsService.start(request);\n\n    LOGGER.info(\"Response: \" + response);\n  }\n}\n"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"REST API","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"import java.net.*;\nimport java.net.http.*;\nimport java.util.*;\nimport java.nio.charset.StandardCharsets;\nimport java.util.stream.Collectors;\n\npublic class App {\n  public static void main(String[] args) throws Exception {\n    var httpClient = HttpClient.newBuilder().build();\n\n    var payload = String.join(\"\\n\"\n      , \"{\"\n      , \" \\\"commands\\\": [\"\n      , \"  {\"\n      , \"   \\\"command\\\": \\\"dial\\\",\"\n      , \"   \\\"callName\\\": \\\"origin\\\",\"\n      , \"   \\\"from\\\": {\"\n      , \"    \\\"type\\\": \\\"PHONE\\\",\"\n      , \"    \\\"phone\\\": {\"\n      , \"     \\\"number\\\": \\\"+15551234567\\\"\"\n      , \"    }\"\n      , \"   },\"\n      , \"   \\\"to\\\": {\"\n      , \"    \\\"type\\\": \\\"PHONE\\\",\"\n      , \"    \\\"phone\\\": {\"\n      , \"     \\\"number\\\": \\\"+15559876543\\\"\"\n      , \"    }\"\n      , \"   },\"\n      , \"   \\\"dialTimeoutDurationSeconds\\\": 30,\"\n      , \"   \\\"maxCallDurationSeconds\\\": 3600,\"\n      , \"   \\\"events\\\": {\"\n      , \"    \\\"onAnswer\\\": [\"\n      , \"     {\"\n      , \"      \\\"command\\\": \\\"messages\\\",\"\n      , \"      \\\"messages\\\": [\"\n      , \"       {\"\n      , \"        \\\"type\\\": \\\"SAY\\\",\"\n      , \"        \\\"say\\\": {\"\n      , \"         \\\"text\\\": \\\"Hello, your call is now connected.\\\",\"\n      , \"         \\\"voiceName\\\": \\\"Emma_3\\\"\"\n      , \"        }\"\n      , \"       }\"\n      , \"      ]\"\n      , \"     }\"\n      , \"    ],\"\n      , \"    \\\"onHangup\\\": [\"\n      , \"     {\"\n      , \"      \\\"command\\\": \\\"hangup\\\"\"\n      , \"     }\"\n      , \"    ]\"\n      , \"   }\"\n      , \"  }\"\n      , \" ]\"\n      , \"}\"\n    );\n\n    HashMap<String, String> params = new HashMap<>();\n    params.put(\"serviceId\", \"6e124178-c29d-46a5-943c-5c2ae544aade\");\n\n    var query = params.keySet().stream()\n      .map(key -> key + \"=\" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))\n      .collect(Collectors.joining(\"&\"));\n\n    var host = \"https://voice.api.sinch.com\";\n    var projectId = \"YOUR_projectId_PARAMETER\";\n    var pathname = \"/v2/projects/%7BprojectId%7D/calls\";\n    var request = HttpRequest.newBuilder()\n      .POST(HttpRequest.BodyPublishers.ofString(payload))\n      .uri(URI.create(host + pathname + '?' + query))\n      .header(\"Content-Type\", \"application/json\")\n      .header(\"Idempotency-Key\", \"stringstringstri\")\n      .header(\"Authorization\", \"Basic \" + Base64.getEncoder().encodeToString((\"<username>:<password>\").getBytes()))\n      .build();\n\n    var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());\n\n    System.out.println(response.body());\n  }\n}\n","lang":"java"},"children":[]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This example highlights the following required to successfully make a Voice API v2 call using the Sinch Java SDK:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#client"},"children":["Client initialization"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#voice-v2-domain"},"children":["Voice domain access"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#endpoint-categories"},"children":["Endpoint usage"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#request-and-query-parameters"},"children":["Field population"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"client","__idx":2},"children":["Client"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"initialization","__idx":3},"children":["Initialization"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To start using the SDK, you need to initialize the main client class and create a configuration object to connect to your Sinch account. You can find all of the credentials you need on your Sinch ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://dashboard.sinch.com"},"children":["Build Dashboard"]},"."]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"US Region","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"import com.sinch.sdk.SinchClient;\nimport com.sinch.sdk.models.Configuration;\nimport com.sinch.sdk.models.SMSRegion;\n\npublic class App {\n    \n    public static void main(String[] args) {\n        SinchClient client = new SinchClient(Configuration.builder()\n                                    .setProjectId(\"YOUR_project_id\")\n                                    .setKeyId(\"YOUR_access_key\")\n                                    .setKeySecret(\"YOUR_access_secret\")\n                                    .setSmsRegion(SMSRegion.US)\n                                    .build());\n    }\n}\n","lang":"java"},"children":[]}]},{"$$mdtype":"Tag","name":"TabItemFragment","attributes":{"label":"EU Region","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"import com.sinch.sdk.SinchClient;\nimport com.sinch.sdk.models.Configuration;\nimport com.sinch.sdk.models.SMSRegion;\n\npublic class App {\n    \n    public static void main(String[] args) {\n        SinchClient client = new SinchClient(Configuration.builder()\n                                    .setProjectId(\"YOUR_project_id\")\n                                    .setKeyId(\"YOUR_access_key\")\n                                    .setKeySecret(\"YOUR_access_secret\")\n                                    .setSmsRegion(SMSRegion.EU)\n                                    .build());\n    }\n}\n","lang":"java"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Note"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"voice-v2-domain","__idx":4},"children":["Voice v2 domain"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Sinch Java SDK organizes different functionalities in the Sinch product suite into domains. These domains are accessible through the client. For example, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.voice().v2().[endpoint_category]().[method()]"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"endpoint-categories","__idx":5},"children":["Endpoint categories"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the Sinch Java SDK, Voice API v2 endpoints are accessible through the client. The naming convention of the endpoint's representation in the SDK matches the API:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/BatchesService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().batches()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/CallsService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().calls()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/ServicesService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().services()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/SessionsService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().sessions()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/SinchEventsService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().sinchEvents()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developers.sinch.com/sdk/sinch-sdk-java/2.3.0/com/sinch/sdk/domains/voice/api/v2/SvamlService.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().svaml()"]},{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/external-blue.5a59beb5e5a442f78b530509ddf6b5d0fa705285ff8181e59adf96b5c2c73e25.33310b29.svg","alt":"external"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"MessagesCommand greeting =\n    MessagesCommand.builder()\n        .setMessages(\n            Collections.singletonList(\n                SayMessage.builder()\n                    .setText(\"Hello, your call is now connected.\")\n                    .setVoiceName(\"Emma\")\n                    .build()))\n        .setEvents(\n            MessageEvents.builder()\n                .setOnFinish(Collections.singletonList(HangupCommand.HANGUP_COMMAND))\n                .build())\n        .build();\n\nDialCommand dial =\n    DialCommand.builder()\n        .setCallName(\"Java_SDK_Snippet_Call\")\n        .setFrom(Phone.builder().setNumber(sinchPhoneNumber).build())\n        .setTo(Phone.builder().setNumber(recipientPhoneNumber).build())\n        .setEvents(\n            CallEvents.builder().setOnAnswer(Collections.singletonList(greeting)).build())\n        .build();\n\nStartCallRequest request =\n    StartCallRequest.builder().setCommands(Collections.singletonList(dial)).build();\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"request-and-query-parameters","__idx":6},"children":["Request and query parameters"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests and queries made using the Java SDK are similar to those made using the Voice v2 API. Path parameters, request body parameters, and query parameters that are used in the API are all passed as arguments to the corresponding Java method."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For example, consider this example in which the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get()"]}," method of the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["voice().v2().calls()"]}," class is invoked:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","header":{"controls":{"copy":{}}},"source":"Call response = callsService.get(callId);\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"JSON","header":{"controls":{"copy":{}}},"source":"\nurl = \"https://voice.api.sinch.com/v2/projects/${projectId}/calls/${callId}\"\n\n","lang":"JSON"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the Voice API v2, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["callId"]}," would be included as a path parameter in the request. With the Java SDK, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["callId"]}," parameter is used in an object passed as an argument in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["get()"]}," method."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"responses","__idx":7},"children":["Responses"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Response fields match the API responses. They are delivered as Java objects."]}]},"headings":[{"value":"Sinch Java SDK for Voice API v2","id":"sinch-java-sdk-for-voice-api-v2","depth":1},{"value":"Syntax","id":"syntax","depth":2},{"value":"Client","id":"client","depth":2},{"value":"Initialization","id":"initialization","depth":3},{"value":"Voice v2 domain","id":"voice-v2-domain","depth":2},{"value":"Endpoint categories","id":"endpoint-categories","depth":2},{"value":"Request and query parameters","id":"request-and-query-parameters","depth":2},{"value":"Responses","id":"responses","depth":2}],"frontmatter":{"seo":{"title":"Java SDK Reference | Voice API v2 | Sinch","description":"Learn the syntax of the Sinch Java SDK for Voice API v2."},"product":"Voice API v2"},"lastModified":"2026-10-15T16:44:08.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/voice-2.0/sdk/java/syntax-reference","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}