DEV Community

Cover image for How To Make and Receive calls using any Programming language ?

How To Make and Receive calls using any Programming language ?

Ameed Jamous
Founder @TelecomsXChange (TCXC) | Tech Evangelist @Telestax
・2 min read

Programmable Voice API

Learn how to make and receive phone calls programmatically using Restcomm API (Twilio Alternative) where you can use / bring your own carrier.

A Call represents a connection between a phone or user agent and Restcomm CPaaS. This may be inbound or outbound. The Calls list resource represents the set of phone calls originated and terminated from an account.

curl -X POST  \
   -d 'From=16175551212' \
   -d 'To=16172221212' 
   -d 'Url=' \
   -u 'YourAccountSid:YourAuthToken'

Making and receiving a call in JAVA

import java.util.Base64;

public class JavaSampleClass {
   // Provide your Account Sid and Auth Token from your Console Account page
   public static final String ACCOUNT_SID = "my_ACCOUNT_SID";
   public static final String AUTH_TOKEN = "my_AUTH_TOKEN";

   public static void main(String[] args) throws Exception {
      String userAndPass = ACCOUNT_SID + ':' + AUTH_TOKEN;
      String encoded = Base64.getEncoder().encodeToString(userAndPass.getBytes());

      URL url = new URL(("" + ACCOUNT_SID + "/Calls.json");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("From=16175551212&" +
        "To=16172221212" +

      // Add your business logic below; response code can be obtained from 'conn.getResponseCode()' and input stream from 'conn.getInputStream()'

You can also provide a list of events you are interested in getting notified on and provide a URL to receive them at. Here’s an example for receiving answered and completed events. The callbacks will be made at http://status.callback.url

curl -X POST  \
   -d 'From=16175551212' \
   -d 'To=16172221212' \
   -d 'Url=' \
   -d 'StatusCallbackEvent=answered,completed' \
   -u 'YourAccountSid:YourAuthToken'

For detailed and updated docs, visit

Discussion (0)