Learn How to Send an SMS with Twilio in 5 Minutes

Twilio is a wonderful communication as a service platform that allows sending SMS messages from your app via a REST API. In this blog post you will learn how to send an SMS message from the Appery.io Server Code in about 5 minutes.

  1. Sign into your Appery.io account (you will also need to have a Twilio account).
  2. Go to the Server Code page.
  3. Server Code has a built-in Twilio SMS plug-in. You just need to add it to your account. Go to the Plugins tab. You will see a list of Server Code plugins:

    Server Code plug-ins

    Server Code plug-ins

  4. Locate the Twilio plugin (Quickly send SMS message with Twilio) and click import. A script called Twilio_SendSMS that sends the SMS will be inserted in the Script panels. A library called Twilio_Base64_library that helps with authentication will also be inserted in the Library panel.
  5. Open the Twilio_SendSMS script:
    var accountSid = ""; //Your Twilio account sid
    var authToken = ""; //Your Twilio account token 
    var twilioUrl = "https://api.twilio.com/2010-04-01/Accounts/";
    
    var from = ""; //Your Twilio number
    
    var to = request.get("to"); //To phone number
    var body = request.get("body"); //Text of the message
    
    var XHRResponse = XHR2.send("POST", twilioUrl + accountSid + "/Messages.json", {
      "body": "To=" + encodeURIComponent(to) + "&From=" + encodeURIComponent(from) + "&Body=" + body,
      "headers": {
         Authorization: "Basic " + encodeBase64(accountSid + ":" + authToken),
         "Content-Type": "application/x-www-form-urlencoded"
      }
    });
    
    Apperyio.response.success(XHRResponse.body, "application/json");

    You need to set the accountSid, the authToken and your Twilio phone number. You can find this information in the Twilio console.

    Twilio SMS

    Twilio SMS

  6. Once you set those values you are ready to test the script. Switch to Script parameters tab.
  7. Add two parameters:
    1. to (that’s the number where the message will be sent)
    2. body (that’s the message)
      These are request parameters into the script (and the API) and are read on lines 9-10.
  8. Switch to Test tab and click the Save and run button.
Testing Twilio SMS API

Testing Twilio SMS API

And this is how it looks on the phone:

SMS message

SMS message

Once you tested the Server Code script, it can be quickly added to your app. Here is a video that shows how to import services into an app. Every Server Code script is also an automatically a REST API. To see the endpoint for this script switch to API information tab. To learn more about Server Code, check our the Server Code YouTube playlist where you will find many short videos.

How to Send a Fax Using Twilio Fax API

twilio_fax

Last week Twilio launched a new API that allows to send faxes. From the very start Appery.io platform made it very simple to connect to any external REST API. We love Twilio API and have an example and video on how to use the SMS API. The Fax API is as elegant and simple to use. In this blog post you will learn how to send a fax using the Twilio Fax API from a Server Code script.

Create a new Server Code script and copy the following script:

var url = "https://fax.twilio.com/v1/Faxes";
var accountSid = "AC3526fbeed7...............";
var token = "8703513246d3f445e............";
var to = "To number";
var from = "Your Twilio number"
var mediaUrl = "https://www.twilio.com/docs/documents/25/justthefaxmaam.pdf";

var XHRResponse = XHR2.send("POST", url, {
   "body": "To=" + encodeURIComponent(to) + "&From=" + encodeURIComponent(from) + "&MediaUrl="+mediaUrl,
   "headers": {
      Authorization: "Basic " + encodeBase64(accountSid + ":" + token),
      "Content-Type": "application/x-www-form-urlencoded"
   }
});

Apperyio.response.success(XHRResponse.body, "application/json");

The script is simple and does a POST request to the Twilio Fax API.

Line 1 is the Twilio Fax API endpoint.

Line 2 and 3 are Twilio Account SID and Auth Token. You can get both from the console dashboard.

Line 4 is where to send the fax (number).

Line 5 is your Twilio number.

Line 6 is a link to a document you want to fax. You can set it to any PDF file accessible via a direct link (or use the sample one provided by Twilio).

Line 8 is where the POST request is invoked with all the information.

Twilio Fax API uses Basic Authentication so the Account SID and Auth Token need to be encoded as Base64. There is an out-of-the-box plug-in that you can add to your account. The plug-in has a function to encode a string as Base64.

  1. Open the dropdown list (on the left) and select Back to list.
  2. Open the Plugins tab.
  3. Find the EncodeBase64 plugin and click insert to add it to your account. The plugin will be listed in the Library section. You can now use it in any other script.
  4. One more step is to add this library as a dependency for your script. Open that script you created. Go to Dependencies tab and click on EncodeBase64_Library.

You are ready to test the script.

Go back to the Script tab and open the Run tab (on the right). Click on Save and run button to invoke the API and send the fax.

The response should look like this:

{
   "date_updated": "2017-04-06T13:13:40Z",
   "date_created": "2017-04-06T13:13:40Z",
   "num_pages": null,
   "api_version": "v1",
   "media_url": null,
   "url": "https://fax.twilio.com/v1/Faxes/FX225bab5034cb8a335c45...............",
   "sid": "FX225bab5034cb8a335c45...............",
   "quality": "fine",
   "duration": null,
   "price_unit": null,
   "price": null,
   "account_sid": "AC3526fbeed7...............",
   "from": "+1415xxxxxxx",
   "to": "+1925xxxxxxx",
   "status": "queued",
   "direction": "outbound"
}

You can navigate to the URL set in the url attribute – there you will be able to see the status of the sent fax (the browser will ask you to login, use the Account SID and Auth Token values).

It can take a few minutes for the fax to be delivered, keep that in mind when testing.

To learn more about Server Code check out our YouTube playlist. Happy faxing.

 

Convert Phone Numbers Into Real Business Intelligence with EveryoneAPI

old_telephone

EveryoneAPI by Telo allows to convert a phone number into real business intelligence with a simple API request. The complete reverse phone append product is simple to use, yet powerful and built for developers by developers. As you probably already know, integrating with any 3rd party REST API using the Appery.io Server Code is also simple. In this blog post, I will show you how to invoke a test a script that calls the Everyone API.

To start, create a new Server Code script with the following code:

var telephone = request.get("telephone");
var url = "https://api.everyoneapi.com/v1/phone/"+telephone;
var auth_token  = "AU83e975.....";
var account_sid = "AC659275.....";

var XHRResponse = XHR2.send("GET", url, {
   "parameters": {
      "auth_token": auth_token,
      "account_sid": account_sid, 
      "pretty": "true"
   }
});
Apperyio.response.success(XHRResponse.body, "application/json");

The only thing you need to do, is to replace the auth_token and account_sid with values from your account. Sign up for an account here. It’s fast and simple.

The phone number for which you want to get information is passed as a parameter to the script (line 1). To test the script, switch to Script parameter tab (on the right side), enter a parameter called telephone and then set it to a test value. Here is an example testing the API using the Appery.io telephone number:

Testing EveryoneAPI

Testing EveryoneAPI

Once you finished and tested the script, you easily import into your app. This video shows how to do that.

Looking for more APIs by Telo? Check out the CallerID Server Code plug-in:

callerid_servercode_plugin

OpenCNAM plug-in

This plug-in creates a Server Code script that integrates with OpenCNAM API. The OpenCNAM API allows you to get caller ID information for phone number provided.

Building a Native App with Ionic, AngularJS, and Appery.io

For years, developers had to make a choice: build a single hybrid app with a so-so user experience, or build a native app for each platform with a great user experience. Developers don’t have to make this choice anymore. By integrating the Ionic SDK into Appery.io, developers can build enterprise HTML5/hybrid apps on a single code base that offer a native experience across all platforms. The Appery.io platform’s visual tooling lowers the skills barrier, empowering a broader base of developers and business analysts to create effective and intuitive mobile applications.

In this tutorial, you will use the Appery.io platform to build a mobile app. The tool set includes:

  • Ionic – native-like UI components
  • AngularJS – UI logic/binding
  • Appery.io App Builder – cloud-based drag and drop designer
  • Appery.io Backend Services – API backend for the app

Read the rest of this entry »

Big Update: New Release Has Social Network Identity Integration and Much More

apperyio_update

The new update has a lot of new features. These features include:

  • Social login and LDAP sign-on for apps
  • Offline capability in apps using the internal database or an external one
  • New Bootstrap and Ionic components
  • Outline page component view

Keep reading to learn more about what’s new in Appery.io.

Read the rest of this entry »

Quickly Add Custom Business Logic to Your App with Server Code

Screen Shot 2015-07-01 at 2.45.21 PM

Appey.io Server Code is a powerful tool that allows you to write custom server-side business logic for your app. These are the benefits you get when you use Server Code:

  • Write and implement any business logic for an app. For example, you can write a script that checks inventory (Database), then sends a push notification, and then sends an e-mail using the SendGrid API
  • Quickly test the script during development
  • JavaScript is the language used to write the script
  • Server Code is based on the popular V8 JavaScript engine. This means you can use any APIs supported by V8
  • A Server Code script is instantly exposed via a REST API. This means you can quickly build a custom API

Read the rest of this entry »

Learn How to Create a Server Code Script to Invoke a REST API in 5 Minutes

Screen Shot 2015-07-01 at 2.45.21 PM

In this 5-minute video you will learn how to invoke a REST API from the server (instead of directly from the client. There are a number of benefits to invoke an API from the server:

  1. JavaScript is the language used to write the script (and you already know JavaScript!)
  2. Additional business logic can be added around the API. For example, in addition to sending an SMS, you can also send an email (SendGrid API)
  3. The API keys and tokens are secure
  4. Script is exposed via REST API (to be invoked from the app)
  5. Script has API to access Appery.io Database, Push
  6. A script can be saved as a library and used in other scripts
  7. Script changes can be made without updating the client (app)
  8. It’s tool to write code 🙂

Check out all the other Build in 5 Minutes videos.

Video: Exposing SQL Database via REST APIs Using API Express

This video shows how to connect to a SQL database using API Express and expose the database via REST APIs. The video then shows how to build a mobile app with the exposed APIs.

API Express: Expose SQL Databases with REST APIs

api_express_logo

Wondering how to access your SQL database from a mobile app? We’ve got the answer. API Express, recently released by Appery.io, can make your existing SQL database RESTful in minutes, allowing you to perform CRUD operations from any external source, whether it’s a mobile app or a web page.

Read the rest of this entry »

How To Send Twilio SMS From Your Mobile App