Google Spreadsheet + JSON + Solve360 CRM
23 febrero 2011 Dejar un comentario
Here a sample code to get a JSON response using Google Apps Script from Solve360 CRM
Based on change some lines of code into the Solve360 Service library for Google Apps Scripts
/**
* Request to the Solve360 API server
* data should be an Array in Short Hand notation
*/
request : function(uri, restVerb, data) {
if (this._credentials == null) {
throw new Error(‘Solve360 credentials are not set’);
}
if (typeof(data) != ‘undefined’) {
data.unshift(‘request’);
data = Xml.parseJS(data).toXmlString();
} else {
data = ‘’;
}
var headers = {
“Authorization” : “Basic “ + this._credentials,
“Accept” : “application/json”,
};
var options = {
“contentType” : “application/xml”,
“method” : restVerb.toLowerCase(),
“payload” : data,
“headers” : headers
};
return UrlFetchApp.fetch(this._url + uri, options).getContentText(); //Xml.parse(UrlFetchApp.fetch(this._url + uri, options).getContentText()).getElement();
}
Making the calling from your own code
function getReport() {
// Loading Solve360Service library
// write here ..
var user = UserProperties.getProperty(USERPROPERTY_USER);
var token = UserProperties.getProperty(USERPROPERTY_TOKEN);
if (user == null || user.length == 0 || token == null || token.length == 0) {
throw new Error(‘Use Solve360 spreadsheet menu to set email and token first’);
}
// Configure service gateway object
Solve360Service.setCredentials(user, token);
var myContacts = Solve360Service.searchContacts([]);//getContactsCategories();
var myContactsJson = Utilities.jsonParse(myContacts);
….
Links
http://code.google.com/googleapps/appsscript/
http://static.solve360.com/gadgets/resources/js/Solve360Service.js
regards
http://Aeegle.com
http://www.aesist.com