Appcelerator Blog

The Leading Resource for All Things Mobile

Titanium Appcelerator Quickie: StackMob API Module Part One

0 Flares 0 Flares ×
Editor’s Note: This post is cross-posted with permission from the Clearly Innovative blog, maintained by Aaron Saunders.


This is an introductory post on using StackMob for the backend services of your mobile applications. The StackMob platform helps you build, deploy and scale your backend while making it very easy for you to add push notifications, social integration and more to your apps. Here is a blog posting on why services like StackMob are a value-add for Appcelerator developers.

Why a PaaS for Mobile Developers Makes Sense

Here is my brief outline on the benefits StackMob provides: More Information Available on website

  • REST Based API
  • Custom Code Integration
  • Social Media Integration
  • Push Notification
  • Separation of Production and Staging Environments

In this first part of a three part series we will cover a very basic implementation using a Javascript REST based API. StackMob provides an IOS and Android SDK so you can create a native module if you like. In the last few weeks I created a functioning IOS module and have started working on an Android module that I will release to the Marketplace soon.

In this initial example I have created, there are two simple objects: users and photos. We will expand on the relationship in a later posting, but this is good enough for now.

First you need to go to StackMob and get an account. They are still in beta, but if you indicate that you are trying to integrate with Appcelerator, they will give you priority access.

Create An App

StackMob - Create an Application

Here we will create our user object. StackMob allows us to specify that the object is a user object and this is how we can log in and out of our application. No trying to roll your own authentication method. It is using xAuth over HTTPS, so you are all set.

Click “Create a Schema” to Add the User Object

StackMob - Create a Schema-1

then enter the appropriate information for your user object

StackMob - Edit a Schema-1

I have added another object called Photos. I am using it to post data to the server. StackMob made the integration with Amazon S3 very easy.
Here is my photo object
StackMob - Edit a Schema

When you are all done, you should have something that looks similar to this, if you have been following along.

StackMob - Manage Schemas - people_interact-1-2

In a few minutes, I created my app and created two objects using their platform. Lets test out what we created in the Console before we even get to code; click on the link that says “Console”

StackMob - Manage Schemas - people_interact

This will bring you to the Console that will allow you to go through all of the CRUD methods to test your objects you have created

StackMob - Console

If you click GET for the default method our application, you will get a listing of the schema you have created based on your application object; the output should look similar to this.

Ok enough StackMob, where is the Appcelerator code….

First you need to initialize the module. I have created a file called credentials which holds your StackMob credentials and associated application information. Here is what the file looks like.

Now with the credentials set, here is how you intialize the module.

And finally, here is how you create a user object to go along with the object you created in the console.

the successful output from the module should look something like this.

The client create method is a nice wrapper around a POST of the REST API call to create the user object. The whole objective of the module I created is to cut down on the time spent coding the oAuth API and get straight to doing productive things. The way the module is created, it will take the parameters and return the results as a JSON object

Here we make an API call through the module to get the list of all of the user(s) we have created in the system.

And to get a specific user, we can pass in the value for the user name in the GET query like this.

In Part Two I will cover setting up the Amazon S3 Integration and the uploading of image files to the system.

Complete Listing


0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×


  1. hello

    Where can I download stackmob-module.min?

    • Aaron Saunders

      i aplogize the original link was not working it has since been updated

  2. Thanks. It’s good example. I hope to see part two ASAP! Cheer!

  3. HairgamiMaster

    Awesome! Thanks so much. Can’t wait for part two. Been waiting for something like this for a while.

  4. Ive already signed up.
    Curious to see what they will charge for requests/transactions and they definitely will.
    This is pretty much an answer to , if i’m not mistaken.

  5. HairgamiMaster

    Hi Aaron-
    Next time around, would you mind including a non-minified version of the stackmob-module.js file? It’d make it much easier to learn from and debug.

    Thanks again!

  6. HairgamiMaster

    I added a login method to your StackMob code:

    Client.prototype.login = function (a) {
    action: a.className + “/” + a.objectId,
    method: “login”,
    params: a.params,
    success: a.success,
    error: a.error

    Calling it like so:

    className : ‘user’,
    params : {
    ‘username’ : “freddymac”,
    ‘password’ : ‘1234’,
    success : function(data){“logged in succesfully”);
    error : function(data){“couldn’t log in.”);


    Does that look right? I’m not sure if that’s all that’s required to login, but its not working- I think its on their end.

  7. HairgamiMaster

    Code cleaned up:

  8. Aaron Saunders

    Here is the answer to your login question:

    User Login with StackMob – Titanium Appcelerator Quickie: StackMob API Module Part 1a #appcelerator #stackmob

  9. Beamer

    Doesn’t look like you can add the ordering headers outlined here:

    Is this possible?

  10. Let me take a look at it tomorrow and I will post some code/update you to what I have found.

    when i first started working in the blog posting, I dont believe that functionality was documented… but thx for the heads up

  11. Steve Harman

    REALLY looking forward to your native module Aaron & thanks for this blog posting, very useful.

    Kind Regards,


  12. Beamer

    Any update?


    this posting show how to use the headers for ordering the result set

Comments are closed.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×