DEV Community

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

Posted on

1 1

How To Make and Receive calls using any Programming language ?

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 https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Calls.json  \
   -d 'From=16175551212' \
   -d 'To=16172221212' 
   -d 'Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml' \
   -u 'YourAccountSid:YourAuthToken'


Enter fullscreen mode Exit fullscreen mode

Making and receiving a call in JAVA

import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
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(("https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/" + ACCOUNT_SID + "/Calls.json");
      HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoded);
      conn.setRequestMethod("POST");
      conn.setDoOutput(true);
      DataOutputStream os = new DataOutputStream(conn.getOutputStream());

      // Update POST parameters accordingly
      os.writeBytes("From=16175551212&" +
        "To=16172221212" +
       "Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml");
      os.close();

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

Enter fullscreen mode Exit fullscreen mode

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 https://cloud.restcomm.com/restcomm/2012-04-24/Accounts/ACCOUNT_SID/Calls.json  \
   -d 'From=16175551212' \
   -d 'To=16172221212' \
   -d 'Url=https://ACCOUNT_SID:AUTH_TOKEN@mycompany.com/restcomm/demos/hello-play.xml' \
   -d 'StatusCallbackEvent=answered,completed' \
   -u 'YourAccountSid:YourAuthToken'

Enter fullscreen mode Exit fullscreen mode

For detailed and updated docs, visit https://cloud.restcomm.com/docs/api/calls-api.html

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more