Skip to content

Instantly share code, notes, and snippets.

@leumund
Created October 20, 2012 20:21
Show Gist options
  • Save leumund/3924645 to your computer and use it in GitHub Desktop.
Save leumund/3924645 to your computer and use it in GitHub Desktop.
Google App Script Prototype for Base CRM
// Sample File for Interaction with the Base CRM API via Google Apps Scripts for Spreadsheet
// The below script is getting a Token based on email and password authentification from the base API
// and is writing in the active spreadsheets all the deals with the described status
// I'm not a programmer, so see it as a prototype to checkout the possibilities.
// 2012 Christian Leu - www.leumund.ch
function deals() {
var email = "base crm e-mail adress";
var password = "base crm password";
var token = authorize(email, password);
var month = Utilities.formatDate(new Date(), "GMT", "MM_yyyy");
var header = {'X-Pipejump-Auth':authorize(email, password)};
var options = {"headers":header};
// aktuelles Spreadsheet
//var sheet = SpreadsheetApp.getActiveSheet();
var sheet = SpreadsheetApp.create("CL Status Quotes & Tenders " + month);
// Kopfzeilen schreiben
sheet.appendRow(["Account","Beschreibung","Erstellt","Umsatz","Status"]);
var index;
var stage = ["incoming", "qualified", "quote", "closure", "unqualified"];
for (index = 0; index < stage.length; ++index) {
// console.log(a[index]);
var page="1";
while (page > 0){
var result = UrlFetchApp.fetch("https://sales.futuresimple.com/api/v1/deals.json?stage=" + stage[index] +"&page=" + page, options);
var o = Utilities.jsonParse(result.getContentText());
var data = o.value;
//return o[0].deal.name;
// return o;
Logger.log("check" + o.length);
if (o.length < "20") { page = "0"} else { page++ }
for (var i in o) {
sheet.appendRow([o[i].deal.deal_account.name,o[i].deal.name,o[i].deal.created_at.substring(0,10),o[i].deal.scope +"€",o[i].deal.stage_name]);
}
}
}
}
// Authorize the client
function authorize(email, password) {
var payload = {
"email" : email,
"password": password,
};
var options =
{
"method" : "post",
"payload" : payload
};
var result = UrlFetchApp.fetch("https://sales.futuresimple.com/api/v1/authentication.json",options);
var token = Utilities.jsonParse(result.getContentText());
return token.authentication.token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment