API Development

Accessing Axway Mobile Backend Service (MBS) from Axway’s Integration Builder

Accessing Axway Mobile Backend Service (MBS) from Axway’s Integration Builder

In a previous blog post, we described how to access Axway’s MBS (Mobile Backend Service) from a Node.js app. In this blog post, we’ll describe how to access Axway’s MBS from Axway’s Integration Builder.

Some advantages of using Integration Builder over creating your own Node app are:

  • Create your application with low code using a graphical flow editor instead of writing lots of Javascript code
  • Hosted SaaS (Software as a Service) solution so you need not worry about hosting your Node app
  • Over 150 out of the box connectors to popular services for data mashups

Currently, an Integration Builder connector for the MBS does not exist. However, the MBS is accessible via REST API so we can leverage Integration Builder’s HTTP Request step for making REST API calls to the MBS.

MBS Rest API

You can learn about the MBS REST APIs here and here.

Most MBS API requests require a user login using the Users object. The REST API for logging in is shown below:

curl -b cookies.txt -c cookies.txt -F "login=mgoff@appcelerator.com" -F "password=food" https://api.cloud.appcelerator.com/v1/users/login.json?key=&pretty_json=true

As you can see above, you’ll need your MBS App Key as described here.

The REST API for querying the CustomObjects object is shown below:

curl -c cookies.txt -b cookies.txt -X GET --data-urlencode 'where={"color":"blue","coordinates":{"$nearSphere":[-122.1,37.1], "$maxDistance" : 0.00126}}' --data-urlencode 'order=-purchased_at' "https://api.cloud.appcelerator.com/v1/objects/car/query.json?key=&pretty_json=true&count=true"

What is not obvious from the curl example above (but is explained here) is that the session_id needs to be sent with all API requests that require a logged in user. In the above examples, the session_id is stored in the cookies.txt file.

Let’s look at how to make these calls from Integration Builder.

Integration Builder HTTP Requests

A simple test flow for exercising the MBS APIs that we’ll refer to in this post is shown below:

The flow logs in with an MBS user account and queries a CustomObject called approvals. You can see a common Integration Builder design pattern where we prepare for the HTTP Request by creating the URL and any other required items (body, query, etc…) and then we make the HTTP Request in the next step.

User Login

Let’s start by logging into the MBS app.

The prepareLoginMBSUser JS Script step code is shown below:

let url = 'https://api.cloud.appcelerator.com/v1/users/login.json?pretty_json=true&key='+config.mbsAppKey;

let body = {
"login": config.mbsUsername,
"password": config.mbsPassword
}

done({url:url, body:body});

This step is creating the HTTP Request URL and Body.

As you can see above, the MBS App Key, username and password are stored as flow instance variables and are set up when you create an instance of your flow as shown below:

The loginMBSUser HTTP Request step is shown below:

You can see how we are accessing the output of the prepareLoginMBSUser step in the HTTP/S URL and the Body as follows:

  • HTTP/S URL = ${steps.prepareLoginMBSUser.url}
  • Body = ${steps.prepareLoginMBSUser.body}

You can see the response to user login in Integration Builder below:

Note the session_id in the response above

Custom Object Query

Now let’s query a CustomObject.

The prepareGetApprovals JS Script step code is shown below:

let url = 'https://api.cloud.appcelerator.com/v1/objects/'+config.customObject+'/query.json?pretty_json=true&count=true&key='+config.mbsAppKey+'&_session_id='+steps.loginMBSUser.response.body.meta.session_id;

done({url:url});

Here we are creating the HTTP Request URL.

Note that we are passing in the session_id returned in the prior step (steps.loginMBSUser.response.body.meta.session_id).

The getMBSCustomObjectApprovals HTTP Request step is shown below:

You can see how we are accessing the output of the prepareGetApprovals step in the HTTP/S URL as follows:

  • HTTP/S URL = ${steps.prepareGetApprovals.url}

You can see the response to the custom object query in Integration Builder below:

Summary

In this blog post, we saw how we can use Integration Builder to access Axway’s MBS. We exercised the Users and CustomObjects REST APIs. Now we can proceed to create a full-fledged app. For example, we can look for newly approved approvals and send a push notification to the approval requestor. We’ll cover this in a future blog post.

 

Discover more about Axway Integration Builder–scheduled triggered flow example.