Update Nov2017
UPDATE:  parse.com as now been closed and moved to parseplatform.org. I will update the content of this page an move the back-end to this platform

Google Apps Script already has a noSQL database – scriptDB. I use it a lot, and have plenty of examples on this site. When I was developing parse.com api class for VBA , part of the motivation was that I would be able to share data across many platforms (IOS,Android,javScript etc) – including Google Apps Script. As you will know if you a regular visitor on this site, From VBA to Google Apps Script is a regular topic, and creating a GAS version of parse.com – nosql database for VBA was pretty straightforward. Since the implementation is very similar, I recommend you read up on parse.com – nosql database for VBA for concepts and getting started with Parse.

NOTE: You can now use Database abstraction with google apps script to access parse as a backend. If you want to use this library directly,  for compatibility and performance reasons, and because of the changes in GAS Propertystores, I recommend you use the cParseCom implementation of getParsed, as per the example below, where you have set up a property that looks like this in your key store.
{applicationID:”your Parse-applicationID”, restAPIKey:”your Parse-REST-API-Key”}
function tDurect(){
  var userStore = PropertiesService.getUserProperties();
  var parseCom = cParseCom.getParsed("gasParseData",JSON.parse(userStore.getProperty("parseKeys")));
}

Here are  a few  primer slides to get started

Authentication

Note – although the section below still works, it has been superseded by the cParseCom.getParsed() function, as mentioned at the beginning of this article.

Just like in the VBA version, there is a one off authentication needed to register your credentials. Once done, you don’t need to bother with them again as the API looks in your UserProperties for an encrypted version of them. For more on encryption used see this post.

The one off code you need looks like this.
function firstTimeParseCom () {
  // run this once for each user/scope combination
    parseCom.setRegistryPackage ( "parse","default",{restAPIKey: "your rest API key",
                          applicationID:"your application id"});

}


A note about UserProperties and libraries.

  • In the VBA version, credentials are encrypted and stored in the Windows registry. In the GAS version, they are stored in your UserProperties. This means they are available to any script you are running, but not to libraries you are using. I’ll provide the library keys for all this later, but in order to keep your credentials private, I recommend the following setup.
    A script library called parseCom. This is yours, and its main function is to link to the parse libraries, but also to your credential in your UserProperties. Any other scripts or workbooks you write would reference this. I’ll provide the code you need to copy into this script.
  • A one off script in which you store credentials, that’s private to you. It would reference your parseCom library and its contents are the firstTimeParseCom() function.
  • the cParseCom library. This is a shared library I provide that contains the API code. You would reference that in your parseCom library. There is no need to reference it directly anywhere else.
  • As many scripts or workbooks as you like that want to use parse.com. They would all reference your parseCom library.

Something like this

Example workbook script

Let’s say you want to be able to create a a couple of parse Tables (they are called classes) from a workbook. Your script would look this, and you would include a reference to you parseCom library to make it all happen.

function testPopulate() {
  populateFromName ("gasParseCustomers");
  populateFromName ("gasParseData");
}
function populateFromName (sheetName) {
   parseCom.populateFromSheetValues(SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getDataRange().getValues(), sheetName);
}

parseCom library

This would be a standalone script that would act as a gateway to the parse API, and also access your UserProperties for your parse credentials. The code in it doesn’t need to be modified, just copied into a script that you own.
And here’s the code to do it. You can take a copy of this script. There are also some examples there.

// to use parse.com from google apps script you need
// this module
// the cParseCom library
// since credentials are stored in your UserProperties stuff in this module cannot be part of the shared of the library, which canot access your userproperties
//module parseCom skeleton created by excelLiberation@ramblings.mcpher.com at 11/27/2013 5:28:43 PM

// in order to bring into line with the dbabstraction method, and to take account of the new properties service - i recommend the use of the version of this in 
// the cParseCom library. 

function getParsed (parseClass,optStore) {
  return new cParseCom.cParseCom().init(parseClass,findRegistryPackage());
}

function getRegistryPackage () {
  var s =  UserProperties.getProperty("xliberation");
  return s ? JSON.parse(decrypt(s)) : {credentialStore:[]};
}

function findRegistryPackage(authFlavor,scopeEntry,package) {
  authFlavor = authFlavor || "parse";
  scopeEntry = scopeEntry || "default";
  var p = (package || getRegistryPackage()).credentialStore;
  for (var i=0 ;i<p.length ;i++) {
      if (p[i].authFlavor == authFlavor && p[i].scopeEntry == scopeEntry) {
        return p[i];
      }
  }
  return null;
}

function setRegistryPackage (authFlavor,scopeEntry, ob) {
  authFlavor = authFlavor || "parse";
  scopeEntry = scopeEntry || "default";
  var package = getRegistryPackage();
  var p = findRegistryPackage(authFlavor,scopeEntry,package) ;
  if (!p) { 
    p = {scopeEntry:scopeEntry,authFlavor:authFlavor};
    package.credentialStore.push(p);
  }
  for (var k in ob)p[k] = ob[k];
  
  UserProperties.setProperty("xliberation",encrypt(JSON.stringify(package)));
  
}

function encrypt (s) {
  return encryptMessage (s);
}

function decrypt(s) {
  return decryptMessage (s);
}
function getSalt() {
  return "the stars that play with laughing sam's dics";
}
function encryptMessage (s) {
  return sjclEncryption.encryptMessage(s, getSalt());
}
function decryptMessage ( s) {
  return sjclEncryption.decryptMessage(s, getSalt());
}

Adding a reference to cParseCom

Before you can use your copy of parseCom, you’ll need to reference the cParseCom library – here’s the resource property

MMaKU0wHrNShUwFypY3nM8iz3TLx7pV4j

Authentication for the first time.

As described earlier, set up your credentials in your User Properties by making a private script, adding a reference to your parseCom library, entering your parse credentials and running this function,

function firstTimeParseCom () {
  // run this once for each user/scope combination
    parseCom.setRegistryPackage ( "parse","default",{restAPIKey: "your rest API key",
                          applicationID:"your application id"});

}

Now you are good to go. All scripts you write will reference your parseCom library.

Here’s some more detail and examples
For help and more information join our forum,follow the blog or follow me on Twitter .