How to Send a Fax with Appery.io and Twilio Fax API

Twilio launched a new API that allows sending 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. If you fax the pre-set PDF file then yon you will the following fax:

twilio-just-the-fax-man
Twilio sample fax

To learn more about Server Code check the Appery.io YouTube playlist. Happy faxing.

Video: How to Call 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 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.

If you like this video, check the Appery.io YouTube channel for many more short videos to help you build apps faster.

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

apperyio_ondemand_sc_aex_scheme

Appery.io had a strong 2016 and inches closer and closer to 400,000 developers. At the same time, the constant platform updates we roll out add more benefits, services, features, and options. Even without the constant updates, supporting a platform with so many developers would not be a simple task. Our platform has to be ready for continuous updates, increased load, and new user requests and requirements.

We want to provide high SLA level services and avoid unexpected slowdowns and downtimes for customers’ apps even during peak hours. To provide the required scalability and resilience, we rely on industry leader Amazon Web Services and its various features such as Auto Scaling, Launch Configurations, and CloudWatch.

In this blog post you will learn how exactly we ensure scalability and resilience for Appery.io API Express and Server Code services.

Continue reading on the Appery.io blog.

 

22 Things You Should Know About Appery.io Server Code

 

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 try Appery.io? Sign up for a free trial account in seconds.

Watch the Server Code YouTube playlist to learn more.

How to Convert Phone Numbers Into Real Business Data with EveryoneAPI

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:

everyoneap_servercode.png
AnyoneAPI Server Code script

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.png
Caller ID Server Code 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.

How to Connect to FullContact API From Appery.io Server Code

FullContact Developer APIs such as Person API, Company API, Email API and others can provide social profiles in an app, improve contacts in address book, enrich CRM information, and create marketing campaigns.

To make it simple to use FullContact API, we created a Server Code plug-in that quickly creates a script to invoke the Person API. You only need to set the FullContact API key. The following animated GIF shows how to insert the FullContact plug-in and its script:

fullcontact_servercode

Once you set the API key, it’s fast to test the script and the API. Switch to Run tab to test the script. The script comes with a sample email. Feel free to change the input data.

FullContact_ServerCode_run-1024x429.png
Script testing

You can also set the email as a script parameter. Update the script code to look like this:

var email = request.get("email");

and then add the parameter on Script parameters tab.

Using the Server Code plug-in for FullContact API it’s fast and simple to invoke the Person API. Using this plug-in as a starting point, you can update the script to include other API parameters or use other APIs.

A Quick Guide to Sending Push Notifications

Being able to send Push Notifications to users is one of the fundamental capability in an enterprise mobile app. Appery.io platform comes with Push Notifications component out-of-the-box and allows you quickly to send targeted messages to iOS and Android devices. In this blog post we will show the four ways to send a Push Notification message to a user:

  1. Push Notifications Console.
  2. Server Code Push Notifications API (server-side).
  3. Push Notification REST API.
  4. Customer Console.

Push Notifications Console

This first option is probably the simplest way to send a Push Notifications once you have installed an app on a device. Select device types, enter the message and send. The Push Notification message should arrive on the registered device instantly.

 

PN_console.png
Push Notifications console.

 

Continue reading “A Quick Guide to Sending Push Notifications”

Quickly Invoke Lyft API from Appery.io Server Code

Appery.io Server Code makes it simple to invoke any external REST API. In this blog post, I will show you how to invoke Lyft API. I will use the Ride Types API to show what types of cars are available based on a location – latitude and longitude. Lyft is a ride sharing company that’s disrupting car ownership and moving forward with self-driving cars initiative.

Let’s start with the tutorial.

The first step is to perform authentication to get an access token to invoke any Lyft API. As the Ride Types API doesn’t use any user data, you can use client credentials for authentication. The script to get an access token looks like this:

var url = "https://api.lyft.com/oauth/token";
var client_id = "<client_id>";
var client_secret = "<client_secret>";

var XHRResponse = XHR2.send("POST", url, {
  "body": {
    "grant_type": "client_credentials",
    "scope": "public"
  },
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Basic "+encodeBase64(client_id+":"+client_secret)
  }
});
Apperyio.response.success(XHRResponse.body, "application/json");

The response will look like this:

{
   "expires_in": 86400,
   "token_type": "Bearer",
   "scope": "public",
   "access_token": "<access_token>"
}

Once you have the access_token, it is as simple to invoke the Ride Types API:

var url = "https://api.lyft.com/v1/ridetypes"; // REST API URL

var XHRResponse = XHR2.send("GET", url, {
  "parameters": {
    "lat": "37.7833", // San Francisco
    "lng": "-122.4167"
  },
  "headers": {
    "Authorization": "Bearer " + &lt;access_token&gt;
  }
});
Apperyio.response.success(XHRResponse.body, "application/json");

The response looks like this, it shows the type of rides available in San Francisco: Lyft, Lyft Line, and Lyft Plus.

{
	"ride_types": [{
		"ride_type": "lyft_line",
		"pricing_details": {
			"cost_per_minute": 23,
			"base_charge": 200,
			"currency": "USD",
			"trust_and_service": 175,
			"cost_per_mile": 115,
			"cancel_penalty_amount": 500,
			"cost_minimum": 475
		},
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_standard.png",
		"seats": 2,
		"display_name": "Lyft Line"
	}, {
		"display_name": "Lyft",
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_standard.png",
		"pricing_details": {
			"cost_minimum": 500,
			"cost_per_minute": 23,
			"base_charge": 200,
			"currency": "USD",
			"trust_and_service": 175,
			"cost_per_mile": 115,
			"cancel_penalty_amount": 500
		},
		"ride_type": "lyft",
		"seats": 4
	}, {
		"display_name": "Lyft Plus",
		"ride_type": "lyft_plus",
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_plus.png",
		"seats": 6,
		"pricing_details": {
			"currency": "USD",
			"cost_minimum": 700,
			"cost_per_mile": 200,
			"trust_and_service": 175,
			"cancel_penalty_amount": 500,
			"cost_per_minute": 30,
			"base_charge": 300
		}
	}]
}

Want to learn how to build mobile apps fast? Check out the Appery.io YouTube channel for videos.

Learn How to Perform Basic Database Operations: Create, Read, Update, and Delete

The Appery.io Backend Services consists of the following components:

  • Database – for storing any app data.
  • Server Code – for writing server-side app logic using JavaScript.
  • API Express – integrating with external systems and APIs.
  • Push Notifications – sending push messages to devices.
  • Web Hosting – publishing and hosting mobile web apps.

In this post, we will show you how a Server Code script integrates with the Database.

One of the most common questions we get is how to work with the database, how to create, edit and delete data. This makes sense as virtually any mobile app needs to store data in a database and perform these basic operations. To access the database, we are going to use Server Code script. Server Code allows writing app logic using JavaScript which will be executed on the server. For example, a script can access the database, send a Push Notification message, sort data and invoke an external REST API. We will start with the most basic operation: how to read data from the database.

The database collection used in this post looks like this:

crud_collection
Database collection.

This can be data collected from a form inside an app – a form that collects information about the user.

Reading Data

Server Code script has out-of-the-box API to access the database to perform all the basic operations. The following script reads all objects from the above collection.

var dbApiKey = "fe7c124b-f7c5-4764-9274-173b56a97102";
var result = Collection.query(dbApiKey, "Data");
Apperyio.response.success(result, "application/json");

One line 2, the script retrieves all the data.

One line 3, the script response is set. A Server Code script is invoked as a REST API. The code on this line defines the API response.

A script can be quickly tested from the Run tab where you can see the JSON data:

 

crud_test
Script testing.

 

Reading data from a database collection is fast and simple. Next, we are going to save data into the database.

Continue reading “Learn How to Perform Basic Database Operations: Create, Read, Update, and Delete”

How to Build and Test an Ionic SMS App

This video shows how to build and test an Ionic SMS app using Nexmo API. The video tutorial first shows how to create a backend to invoke Nexmo API. Then the Ionic app is created which uses the backend. The app is then tested in the browser and on the device using the Appery.io Tester app. The video also shows how to build a binary file for Android and iOS.

Looking for more videos to help build mobile apps? Check out the Appery.io YouTube channel.