Step by Step guide for Google Apps Script proxying

 

In a number of articles, I’ve covered how to use GAS for jsonpOAuth, as a lockbox and various other useful things. There are many threads to pull together in this section, so here’s a step by guide to GAS proxying as described in this post.
Here’s a schematic of the various themes we’ll cover

 
 

Two examples of publishers

 

We will cover 2 examples in this guide, then show how to access them from a variety of external sources. 

  1. Retrieving some data by parameter from an Apps Script ScripDB,  and returning a jSon response.
  2. Executing a existing mashup and enhancing it, and returning a jSon response
 

Steps for first example – retrieve data from scriptDB

 

Most of the code that is referred to in these serious of posts is available in the mcpher shared library.  Please add this library to all any scripts you create.

  1. Create a blank script project, pubstuff, and add the mcpher library. See Using the mcpher library in your code.
  2. Create a second script project, storeinscriptdb, and add the mcpher library. See Using the mcpher library in your code.
  3. pubstuff will host the scriptDB in which you are going to publish all your public data. To create and publish an app to get access to a public scriptDB, follow Hosting your public scriptdb
  4. In storeinscriptdb, create a module to store some data that we will retrieve later. See Store data in scriptdb for how.

Now we can put the whole thing together. Using the URL of your published app from pubstuff, which you created in Hosting your public scriptdb, you can now enter that in a browser with a parameter of ?entry=favorites appended to the Url.

 
<pre>{
    "status": {
        "code": "good",
        "reason": "favorites found in your stuff"
    },
    "results": [
        {
            "siloId": "favorites",
            "help": "for details see ramblings.mcpher.com",
            "timeStamp": 1352116547560,
            "myStuff": [
                {
                    "name": "excel liberation",
                    "url": "ramlings.mcpher.com"
                },
                {
                    "name": "liberation blog",
                    "url": "https://ramblings.mcpher.com/ramblings-blog/"
                }
            ],
            "userStamp": "bruce@mcpher.com"
        }
    ]
}</pre>
 

Steps for second example – enhancing a mashup

 

Most of the code that is referred to in these serious of posts is available in the mcpher shared library.  Please add this library to all any scripts you create. In this example, we are going to take the urbarama mashup, which already uses google apps script to combine 2 APIS, and create another API which refines the result of that and returns the refined results.

  1. Create a blank script project, urbenhanced, and add the mcpher library. See Using the mcpher library in your code.
  2. in urbenhanced, we need to write some code that will execute the original urbabarama mashup as rest query, but will manipulate the results and publish the manipulated results instead. See Enhancing the urbarama mashup for how.

Now we have an enhanced urbarama mashup. Here’s my implementation of this example with a couple of parameters appended.

 

Using the public scriptdb to manage your URLs

 

Now that we have a couple of publishers, the next step is to use the scriptDB to store an accessible version of your growing library of published apps. 

Now take a look at some selected detail in some of these topics.

 
 

Here’s another example of GAS delegation – this time using built in XML.parse to convert XML to JSON and pulling it back to Excel

 

Delegating xml to json conversion to GAS

Update: The Xml service is being deprecated in Apps Script, but has been replaced by something else. The details below ...