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.

ViewFence Appery.io App Helps Home Buyers Review and Rate Homes They Visit

ViewFence Screenshot

About the Company

The ViewFence app was born as an effort to provide unbiased third party opinions about homes, before buyers decide to spend thousands of dollars on the purchase. ViewFence provides a platform where home buyers and real estate agents can write personalized reviews and share objective opinions about the homes they visit.

The Problem

ViewFence recognized that it is important for home buyers to organize, track, evaluate and compare homes as part of the viewing process. Some of the flexibility the app needed to provide included:

  • Clean and consistent interface across multiple mobile devices and platforms
  • Real-time access to unbiased third party opinions and
  • Ability to take photos and share reviews with family and friends

The company was looking to support a rapidly evolving user experience based on feedback from initial beta users. They were looking for a platform that would enable them to innovate faster and incorporate user feedback.

Solution

ViewFence evaluated several mobile application development platforms (MADP). Appery.io stood out for the following reasons:

Intuitive interface and accelerated learning: The online interface and the usage of standard JavaScript constructs enabled the team to quickly get comfortable with the platform. This also eliminated the need for any specialized mobile platform training for the developers.

Quick turnaround time between releases: The companion Appery.io Tester app on iOS and Android platforms enabled the team to rapidly test features on various devices. The “write once deploy everywhere” development approach allowed the team to simultaneously and seamlessly release the app on multiple App stores and seek feedback from the beta users.

Exceptional support: A comprehensive knowledge base, an active online support forum and responsive support staff ensured timely resolutions to development issues.

ViewFence for Android

ViewFence for Android

ViewFence app was built using Appery.io App Builder for jQuery Mobile, Appery.io Database and Appery.io Server Code.

Looking Ahead

With the help of appery.io, ViewFence has been able to launch the app and is looking to further enrich its offering by expanding features to include REST API integration with real estate content providers including MLS and zillow.com.

Install and use the app today at Apple Store and Google Play at the following links:

Apple Store: get the app

Google Play: get the app

Website: http://www.viewfence.com

Appery.io Newsletter (March 2017) – Platform Update, Stored Procedure as an API and Sending Faxes

The Appery.io March newsletter.

April Platform Update

In early March, we rolled out a third platform update for 2017. This was a small update consisting of primarily infrastructure updates and bug fixing. Here is a short list of new benefits:

  • Upgrade to MongoDB version 3.2. This version improves stability and performance for the Appery.io Database
  • The API Express SDK test page is now using the Ace Editor instead of a plain text area. This will help with better output formatting
  • The API Express service test page has been updated with larger output areas (JSON output). It’s now easier to view the service response
  • The scheduled job execution time limit for Server Code is now the same as the regular (non-scheduled) script execution time limit
  • The Plugins tab and its content has been moved inside the Apps tab. A plug-in is always created from an app so it makes sense to list the plug-ins inside the Apps tab

How to Send a Fax Using the Twilio Fax API

Twilio launched a new API that allows sending faxes. From the very start the Appery.io platform made it very simple to connect to any external REST API. We love the Twilio API and their Fax API is just 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. It’s fun.

How to Expose a Database Stored Procedure and a Function as a REST API

Appery.io API Express makes it easy to expose a SQL query as a REST API. Just as easily you can expose a database stored procedure or a database function as a REST API. The following two blogs posts will teach you how to do that:

If you would rather watch a video on how to do this, here is an 8-minute video on how to expose a stored procedure and a function as a REST API.

Learn How Appery.io Helped Deliver: HABITat, an AI-powered Personal Change App

As the market has filled up with trackers of daily habits, Enkr8ia was looking for a cost-effective and intelligent solution to go beyond the tedious stats. Demand for a clean interface and off-line support was prioritized as well as a virtual coach that would require some tricky API integration. Learn how Enkr8ia used the Appery.io platform to build their app.

From Our Services Team: How We Try to Make Our Customers Happy

Read the blog post on how the Appery.io services team works.

Plus, learn how the services team reduced Server Code script testing by 50%.

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.

 

How to Expose a Database Stored Procedure as a REST API

In an earlier blog post I showed you how to expose a relational database function as a REST API. In this blog post you are going to learn how to expose a database store procedure as a REST API.

If you have an existing stored procedure you can use it. If you don’t have a stored procedure, I will show you how to create two simple tables and then create a stored procedure.

The database used in this example is MySQL. The stored procedure will insert the same data into two different tables. The first step is to create two tables.

Here is SQL to create the first table:

CREATE TABLE `message` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `messageText` VARCHAR(255) NOT NULL,
   PRIMARY KEY ( `id` )
)

And here is SQL to create the second table:

CREATE TABLE `backup` (
   `id` INT NOT NULL AUTO_INCREMENT ,
   `messageBackup` VARCHAR(255) NOT NULL,
   PRIMARY KEY ( `id` )
)

This is the SQL for the stored procedure. The stored procedure inserts the same information into both tables – performing two inserts.

CREATE PROCEDURE `message_and_backup`(IN msg VARCHAR(255))
BEGIN
   INSERT INTO `message` (`messageText`) VALUES (msg);
   UPDATE `backup` (`message`) VALUES (msg);
END

It’s a simple but good example. You can make the stored procedure as complex as you need but the process of exposing it as a REST API is the same and is shown next.

To expose the stored procedure as a REST API, create a custom API Express service with one SQL component:

apiexpress-storedprocedure

 

In the SQL component, call the message_and_backup stored procedure passing in the message input. That’s it.

Right away you can test the API Express service:

apiexpress-storedprocedure-test

 

In this blog post you learned how to expose a stored procedure as a REST API. You can as easily expose a custom SQL query or a function as a REST API. To learn more about API Express please visit our YouTube channel.

 

How to Expose a Relational Database Function as a REST API

Appery.io API Express provides an easy way to expose a SQL query as a REST API. You can as easily expose a relational database function as a REST API. In this blog post you will learn how to do that.

A user-defined function is created with CREATE FUNCTION statement. We will use a simple function, one the increments the entered number by 1.

Here is an example for PostgreSQL database:

CREATE OR REPLACE FUNCTION increment(i INT) RETURNS INT AS $$
BEGIN
  RETURN i + 1;
END;
$$ LANGUAGE plpgsql;

And this is an example for MySQL database:

DELIMITER $$
CREATE FUNCTION increment(i INT)
  RETURNS INT
BEGIN
  RETURN i + 1;
END;
$$
DELIMITER ;

To invoke the increment function use this SQL query:

SELECT increment(10);
// will return 11

To expose this function as a REST API, create the following API Express service:

apiexpress_function

Using the SQL component

It uses the SQL component and invokes the same SQL query.

Now you can easily test the API Express service. Entering 100 will return 101:

apiexpress_function_test

Testing the service

 

As you can see, invoking and exposing a custom SQL query as a REST API is simple. Now you also know how to expose a database function as a REST API.

To learn more about API Express and how to integrate with external resources (SQL database, REST API, web service), please go to our API Express YouTube playlist where we have many videos to help you build faster.

Appery.io Newsletter (February 2017)

Our February 2017 newsletter.

Learn What’s New in Our March Platform Update

In early March we rolled out a second platform update for 2017. The update includes these features and benefits:

  • Improved Autocomplete in App Builder for Ionic
  • New Ace Editor in Server Code
  • Instantly Import Any Database Service into an App
  • Better Developer Experience for Testing APIs inside the App Builder and API Express
  • API Express Autogenerated Services Now Support Sorting by Multiple Parameters
  • API Express Database Connection Now Supports Custom Properties
  • Cloud Database Upgrade

Learn more about these new features and benefits in our blog post.

22 Things You Need to Know about Appery.io Server Code

Appery.io Server Code allows you to write app logic with JavaScript that is executed on the server. Custom app logic is placed inside a Server Code script which is then invoked as a REST API from a mobile app. In this post, you will learn everything you should know about Appery.io Server Code.

Video Tutorial: How to Call the WordPress REST API

Watch this short video to learn how to call the WordPress REST API from an Appery.io app. The video shows two approaches to invoking the API. First, it shows how to invoke an API using API Express. Second, it shows how to invoke an API from Server Code.

New Step-by-step Tutorials

Our friends at WEALL published two great step-by-step tutorials on how to build apps with Appery.io. Check them out:

Learn How Dyjit Launched Their App for a New Hospitality Platform Using Appery.io

Dyjit’s vision is to make life better by introducing digital experiences where they do not yet exist. Dyjit’s first product, knowye (know what you eat), is a hospitality platform that transforms the traditional paper menu into a digital marketing channel and enables restaurants to cater to and market to shifting consumer needs. Learn how this app was built.

March Platform Update: Improved Autocomplete, Ace Editor in Server Code, Improved API Testing and More

Learn about our March platform update.

Improved Autocomplete in App Builder for Ionic

Autocomplete is one of the most-loved developer features. You don’t need to remember the variable name, can quickly insert it from the autocomplete list and more importantly it reduces errors. The App Builder for Ionic now has an improved autocomplete feature, it is now available for any property in the Property panel. Simply click Ctrl+Space to see the available values.

appbuilder_ionic_codeassist

New Option to Specify Custom Database Connection Properties in API Express

New Ace Editor in Server Code

Appery.io Server Code source editor has been upgrade to the poplar Ace editor. The new editor provides the following benefits:

  • Improved code snippets to help you write code faster by inserting common code snippets with just a click.
  • Advanced and more powerful code assist to help you write your code faster.
  • Big performance upgrade when working with large source code files.
  • Better error reporting.

servercode_aceeditor

Read the rest of this entry »

22 Things You Need to Know About Appery.io Server Code

servercode_push

Appery.io Server Code allows you to write app logic with JavaScript which is executed on the server. Custom app logic is placed inside a Server Code script which is than invoked as a REST API from a mobile app. In this post you will learn everything you should know about Appery.io Server Code.

  1. Server Code is a server-side component in the Appery.io cloud platform.
  2. The code (logic) is placed inside a script which is executed on the server.
  3. You can write any custom app logic (you have access to most JavaScript APIs).
  4. The language used to write the Server Code script is JavaScript.
  5. A script is invoked as a REST API from a mobile app.
  6. A script can be tested (invoked) inside the Server Code dashboard.
  7. A script can depend on one more more libraries. A library is a reusable script (JavaScript code also).
  8. A script can connect and query the Appery.io Database.
  9. A script can send, manage and schedule Appery.io Push Notificationsa.
  10. A script can connect and invoke any 3rd party (external) REST API.
  11. A script can be secured with a username and password.
  12. A script can be scheduled as Job to run periodically and on schedule.
  13. A script can invoke another script.
  14. You can create versions of a script.
  15. A script has very fast cache called In Memory Data (data lives for 20 minutes).
  16. A script can be invoked from Appery.io API Express service flow.
  17. The script editor comes with Snippets, small reusable code which can be quickly inserted into a script.
  18. Server Code comes with Plug-ins. Plug-ins are scripts and libraries that can be quickly inserted and provide specific functionality such as integration with 3rd party APIs.
  19. A script has a Trace page where you can view console and error messages from script execution.
  20. A script has a Statistics page where you can view various statistics about a script such as how many times a script was invoked.
  21. A  script has a description field which can be invoked via a separate REST API for documentation purpose.
  22. The JavaScript engine used for Server Code is Nashorn.

Want to build your first app? Sign up for a free trial account in seconds.

Watch the Server Code YouTube playlist to learn more.

Appery.io Newsletter (January 2017)

Our January 2017 newsletter.

Big Platform Upgrade: iOS 10, Cordova Update, Automatic APIs Sync and More

At the end of January we had a big platform update with new upgrades and benefits:

  • iOS 10 Support
  • Apache Cordova Upgrade
  • Automatically Sync Backend Services Changes with the App Builder
  • Organize with Folders Inside the App Builder
  • Backend Services APIs Are Now Placed in Folders for Easier Organization
  • Improved Media Manager
  • Improved Synchronization Between App and Server for Apps with Offline Support
  • New Page to Test API Express Services and Offline Support
  • New Auto-login with Offline Support

Learn more about this platform update from our blog.

Exposing a SQL Database via REST APIs: A Video Guide for Developers

Many organizations that are building mobile apps need to connect to and reuse existing internal systems. One of the most common such system is a relational (SQL) database. The following two videos show how to connect and expose a SQL database via REST API using API Express:

Appery.io + Pollfish: How to Integrate a Pollfish Survey into Your App

Our friends at Pollfish, a survey platform company, created a guide to help you monetize Appery.io apps with Pollfish surveys. Integration takes only a few minutes and can boost your revenue up to 20x more compared to any other traditional advertising format out there. Check our the easy-to-use integration guide.

Learn How Appery.io Ensures API Express and Server Code On-demand Deployment

Read this awesome (and technical) blog post by our Dev Ops Engineer Ruslan Kusov on how he ensures API Express and Server Code support on-demandhttps://blog.appery.io/author/rkusov deployment and can be scaled instantly for any platform traffic.

Can You Build a Conference Room Booking App Using Appery.io in 16 Hours?

Yes. We built a Conference Room Booking App using Appery.io in 16 hours. This app helps with the well-known problem of double-booking conference rooms and then looking confused when someone is there when you need to have an important meeting. Learn more about this app.