The VBA API generates REST API requests from your VBA function calls, and needs a Google Apps Script handler to service those requests by communicating with the required scriptDB instance.

You can have multiple handlers, chosen by the URL you used when initializing the VBA cScriptDBcom instance. In this getting started section, I have a handler that is only going to authorize READONLY type requests.
A handler needs a reference to the GAS LIbrary, cScriptDbCom. Add reference to resource ML7nE0jnmV4tCqTYKNkIykai_d-phDA33 to your project when you come to build your own.

Typical Handler code

It is unlikely you will need to make much changes to this code when you come to write your own handler, aside from to adjust the scriptDB dispatcher library reference, and to adjust the type of access based on the user keys. In this case I’m only allowing read operations, regardless of who is accessing.

// this is a handler for cScriptDbCom requests.
// requests to this script should be authenticated with oAuth2
// 2 further authentication parameters are expected in the head of each request, modelled on the parse.com API
// {"X-scriptDb-Application-Id":"somekey","X-scriptDb-REST-API-Key":"someotherkey"}
// these can be used by the caller to decide whether to allow the type of access being requested

var dispatcher = "scriptDbDispatch";
var whatsAllowed = ['query','count','getbyid'];
function doGet(e) {

    return ContentService
            .createTextOutput(scriptDbCom.makeContent(e,"GET",whatsAllowed,eval(dispatcher +".getDb")(e.parameter.library)))
              .setMimeType(ContentService.MimeType.JSON);  

}
function doPost(e) {
    return ContentService
            .createTextOutput(scriptDbCom.makeContent(e,"POST",whatsAllowed,eval(dispatcher +".getDb")(e.parameter.library)))
              .setMimeType(ContentService.MimeType.JSON);  
  
}


function workAround() {
  var x = ScriptDb.getMyDb();
  x.count({});
}
Note that a different handler may well access the same scriptDB via the dispatcher, for example, for an administrator to update it. This is why I recommend separating the Request Handler from the scriptDB dispatcher.

Private handler

In my architecture, I make the url of the readonly handler available publicly, but restrict access to the fully function handler by Google oAuth2 authentication. If necessary I could further refine this access by examining the user keys. Here’s my fully functional handler. The only difference is I don’t restrict access with
var whatsAllowed = ['query','count','getbyid'];
You can get me on  Twitter or the forum, and compare this topic with parse.com – nosql database for VBA and parse.com – noSQL database for GAS so you can see more about choosing about which noSQL database to use.

For help and more information join our forum, follow the blog or follow me on Twitter