A web service / API to programatically create new views on awesome-table.com. This web service is used in all our add-ons connected to Awesome Table.
Web service: URL: https://script.google.com/macros/s/AKfycbwSw3QNc18KQu-y2PO07I54C4WSB2O3ZjrAxZsaTajLrsCiAmw/exec
Parameters
Name | Required | Type | Description |
---|---|---|---|
token | Always | String | The Google OAuth 2.0 access token for the current user Use ScriptApp.getOAuthToken() to get it. The token must contain the user email address.
Call Session.getEffectiveUser().getEmail() to add it to the token.
|
appTitle | Always | String | Your add-on title |
action |
Always |
String (ENUM) | Specify what you want to do:
|
viewSettings | action = "CREATE" or "EDIT" | String | A JSON encoded string containing the Awesome Table view parameters. |
viewId | action = "EDIT" or "GETVIEW" | String | The target view ID |
Awesome Table view parameters
The following JSON template is used for View resources in the Awesome Table API:
var parameterTemplate = { /* paramNameAndId: { r: true, // is required bool: true, // is a boolean, if not specified, is a string d: "default", // default value }, */ // Sheet url: {r: true}, ISpublicSpreadsheet: {bool: true}, sheet: {r: true}, range: {r: true}, download: {bool: true}, // view pageSize: {d:15}, mapHeight: {d:'500px'}, mapRegion: {d:'world'}, numberOfColumns: {d: 4}, numberOfRows: {}, minCardWidth: {d:'160px'}, maxCardWidth: {d:'100%'}, visualizationType: {d: 'Table'}, // Format categoryCaption: {d:'insideFilter'}, backgroundColor: {d:'white'}, dateFormat: {}, customCSS: {}, errorMSG: {}, // advanced settings codeAnalytics: {}, queryOpt: {}, scriptProxy: {}, rangeTemplate: {}, // General settings viewName: {r: true} };
Name | Type | View specific | Description |
---|---|---|---|
viewName | String | the view title | |
url | String | The URL of the Google Spreadsheet | |
sheet |
String |
The name of the sheet to use inside the spreadsheet | |
range | String | The range of cells to retrieve from the sheet | |
rangeTemplate | String | The range of the template cells to retrieve from the sheet | |
SpublicSpreadsheet | Boolean | Specify if the spreadsheet is accessible to anyone without authentication. It speed up the loading in this case. |
|
download | Boolean | Show a button to download the data in a csv file | |
visualizationType | String | The type of AT visualization. Can be one of the following:
|
|
pageSize | String | Table | Number of results by page |
mapHeight | String | Maps MapsWithTable Geochart |
Height of the map, in CSS units for example : "500px" |
mapRegion | String | Geochart | Specify the region code |
numberOfColumns | String | Cards | Set the desired number of columns. Use "none" to let the cards arrange themselves freely. |
numberOfRows | String | Cards | Set the number of row. Use "none" to display all of the cards |
minCardWidth | String | Cards | Set the minimum cards width, in CSS units for example : "160px" |
maxCardWidth | String | Cards | Set the maximum cards width, in CSS units for example : "100%" |
SlideShow_height | String | SlideShow |
Set the SlideShow height, in CSS units for example : "500px" |
SlideShow_duration | Number | SlideShow | Set the SlideShow frame interval in seconds Default to: '7.5' secondes |
SlideShow_captionColor | String | SlideShow | Set the SlideShow title CSS color Default to: "white" |
SlideShow_backColor | String | SlideShow | Set the SlideShow background CSS color Default to: "rgba(0, 0, 0, 0.4)" |
categoryCaption | String | Specify a caption for the filters | |
backgroundColor | String | Set the CSS color of the background of the view. | |
dateFormat | String | Set the date format used in the dateFilter | |
customCSS | String | URL of a custom CSS file. | |
errorMSG | String | Custom Error message, is | |
codeAnalytics | String | Analytics UA code for pageView tracking | |
queryOpt | String | Set the query used when pulling data from the spreadsheet | |
scriptProxy | String | URL of an app script proxy |
Return
A JSON containing the view ID and view URL. Or error if there's an error.
var view = JSON.parse(UrlFetchApp.fetch(AwesomeTableWebService, params).getContentText()); if(view.error) throw view.error.message; Logger.log(view.viewId); Logger.log(view.viewUrl);
Example
In the following example, you will find a fully functionnal app script that demonstrate how to use the Awesome Table Webservice.
warning Don't forget to change the line 89 by your Application Name (It's will be displayed in the future, in the users dashboard).
/** * Create an DEMO Awesome Table view */ function AwTCreateView_demo(){ var view = AwTCallWebService('CREATE', { viewSettings: { // all relevant settings for the view viewName: 'DEMO webservice - ' + (new Date()).toDateString(), visualizationType: 'Table', url: 'https://docs.google.com/spreadsheets/d/1Q2HvdQHQhyLdoAXf94SR70kpFHcA200l2c1-GzHAUNo/edit#gid=1282768648', sheet: 'Form Responses', range: 'A1:H', rangeTemplate: 'Template!A1:B2' } }); Logger.log('View ID :' + view.viewId); Logger.log('View URL :' + view.viewUrl); } /** * List all Awesome Table view created by this app */ function AwTGetAllview_demo(){ var views = AwTCallWebService('LISTVIEW'); // log all view Name & IDs for (var i = 0; i < views.length; i++){ Logger.log(views[i].settings.viewName + ' - ID: ' + views[i].viewId); } } /** * Get an Awesome Table view created by this app and change its name */ function AwTGetEditAview_demo(){ var views = AwTCallWebService('LISTVIEW'); // no existing view for this App if (views.length == 0) return; // just for this example, get a view ID to use with 'getView' var viewId = views[0].viewId; // get (again, for the demo) the view settings for corresponding viewId var viewSettings = AwTCallWebService('GETVIEW', { viewId: viewId }); // log settings for this view Logger.log(viewSettings); // change the view name viewSettings.viewName = 'Webservice DEMO - Edited view Name at ' + (new Date()).toDateString(); // Change the name of the view var view = AwTCallWebService('EDIT', { viewId: viewId, // take care to include ALL previous settings viewSettings: viewSettings }); // log result Logger.log(view); } /** * External call for view creation */ function AwTCallWebService(action, parameters){ var parameters = parameters || {}; // Supercharge token Session.getEffectiveUser().getEmail(); // get OAuth 2 token parameters.token = ScriptApp.getOAuthToken(); // set the action of the call parameters.action = action; // set the App Title parameters.appTitle = "Awesome Table WebService DEMO"; // Stringify viewSettings for the UrlFetch call if (parameters.viewSettings){ parameters.viewSettings = JSON.stringify(parameters.viewSettings); } // web service URL var URL = "https://script.google.com/macros/s/AKfycbwSw3QNc18KQu-y2PO07I54C4WSB2O3ZjrAxZsaTajLrsCiAmw/exec"; // make the call var res = UrlFetchApp.fetch(URL, { method: "post", payload: parameters }).getContentText(); // parse the answer var view = JSON.parse(res); // check for possible error if(view.error){ throw view.error.message; } // use the answer return view; }
Comments
0 comments
Please sign in to leave a comment.