Sending SMS using Plivo in Google App Engine

Now-a-days, sending a SMS is part of the notification in all web and mobile products. We uses Plivo to send SMS notification.

Let me share the code that we used for sending SMS in Java Google App Engine project.

  public static final String PLIVO_VERSION = "v1";
  public static final String PLIVO_AUTH_ID = "YOUR_PLIVO_AUTH_ID";
  public static final String PLIVO_AUTH_TOKEN = "YOUR_PLIVO_AUTH_TOKEN";
  public static final String PLIVO_NUMBER = "YOUR_PLIVO_NUMBER";

  public static void sendSMS(String dst, String text) {

    Client client = Client.create();
    // client.addFilter(new LoggingFilter(System.out));
    WebResource webResource = client
        .resource("" + PLIVO_AUTH_ID
            + "/Message/");
    client.addFilter(new HTTPBasicAuthFilter(PLIVO_AUTH_ID,

    JSONObject object = new JSONObject();
    object.put("src", PLIVO_NUMBER);
    object.put("dst", dst);
    object.put("text", text);
    object.put("type", "sms");
    ClientResponse clientResponse = webResource
        .post(ClientResponse.class, object.toString());

    int status = clientResponse.getStatus();
    if (status >= 400) {

Here we uses Java Rest client jersey to send a request to plivo.

Hope it helps and Have a nice day.

Vote on HN

comments powered byDisqus