X
X

Login

Login if you already have an account

LOGIN

Register

Create a new account. join us!

REGISTER

Support

Need some help? Check out our forum.

FORUM

FYI – it is easy to integrate your backend with other web services

As a Developer, I want to integrate with other web services so that I can offload the integration tasks from my client to my backend.

Many times, you may want to utilize some other web service for the purposes of backend integration. FatFractal makes this really easy.

Let’s say you want to interact with SalesForce data from your backend…

FatFractal support the Common.js standard which includes an http client that let’s you do just about anything you want.

Example:

Here is some code that interfaces to to securely retrieve some information from a SalesForce API:

var hc = require('ringo/httpclient');

exports.getQs = function() {
var loginUrl = "https://login.salesforce.com/services/oauth2/token";
var apiVersion = "v25.0";
var username = "someUsername";
var password = "somePassword";
var securityToken = "someSecurityToken";
var clientId = "someClientId";
var clientSecret = "someClientSecret";

function LoginSF(username, password, securityToken, clientId, clientSecret) {
var data = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password + securityToken
};
var response = JSON.parse(hc.post(loginUrl, data).content);
return response;
}

function QuerySF(instanceUrl, accessToken, queryString) {
var url = instanceUrl + "/services/data" + apiVersion + "/query";
var data = {q: queryString};

var request = {
url: url,
data: data,
method: "GET",
headers: {
Authorization: "Bearer " + accessToken
}
};

var response = JSON.parse(hc.request(request).content);
return response;
}
// perform query
var loginResponse = LoginSF(username, password, securityToken, clientId, clientSecret, true);
var instanceUrl = loginResponse.instance_url;
var accessToken = loginResponse.access_token;
var queryResponse = QuerySF(instanceUrl, accessToken, "SELECT A__c, B__c, C__c FROM D__c");

var records = queryResponse.records;
for (var i = 0; i < records.length; i++) {
// DO SOME STUFF
// E.G. RETURN SOME DATA (SERVER EXTENSION)
// OR TAKE SOME ACTION (EVENT HANDLER)
}
}

What this does is define a function that can be used with an Event Handler or as an API extension with a Server Extension that logs in to an API on SalesForce.com, retrieves an instance_url and access_token that are need to then to execute a query and retrieve a response.

Many other things can be done with this powerful client – have fun!

Kevin

FYI – it is easy to integrate your backend with other web services (for example, SalesForce.com)

As a Developer, I want to integrate with other web services so that I can offload the integration point from my client code to my backend for better performance, security and reliablility.

Many times, you may want to utilize some other web service for the purposes of backend integration. FatFractal makes this really easy. FatFractal supports the Common.js standard which includes an http client that let’s you do just about anything you want.

Let’s say you want to interact with SalesForce data from your backend…

Example:

Here is some code that securely retrieves some information from a SalesForce API that could be used in either a Server Extension of Event Handler:

var hc = require('ringo/httpclient');

exports.getQs = function() {
var loginUrl = "https://login.salesforce.com/services/oauth2/token";
var apiVersion = "v25.0";
var username = "someUsername";
var password = "somePassword";
var securityToken = "someSecurityToken";
var clientId = "someClientId";
var clientSecret = "someClientSecret";

function LoginSF(username, password, securityToken, clientId, clientSecret) {
var data = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password + securityToken
};
var response = JSON.parse(hc.post(loginUrl, data).content);
return response;
}

function QuerySF(instanceUrl, accessToken, queryString) {
var url = instanceUrl + "/services/data" + apiVersion + "/query";
var data = {q: queryString};

var request = {
url: url,
data: data,
method: "GET",
headers: {
Authorization: "Bearer " + accessToken
}
};

var response = JSON.parse(hc.request(request).content);
return response;
}
// perform query
var loginResponse = LoginSF(username, password, securityToken, clientId, clientSecret, true);
var instanceUrl = loginResponse.instance_url;
var accessToken = loginResponse.access_token;
var queryResponse = QuerySF(instanceUrl, accessToken, "SELECT A__c, B__c, C__c FROM D__c");

var records = queryResponse.records;
for (var i = 0; i < records.length; i++) {
// DO SOME STUFF
// E.G. RETURN SOME DATA (SERVER EXTENSION)
// OR TAKE SOME ACTION (EVENT HANDLER)
}
}

Note the inclusion of the httpclient at the top of the source:

var hc = require('ringo/httpclient');

The rest defines a function – “getQs” that can be used with an Event Handler or as an Server Extension that logs in to an API on SalesForce.com, retrieves an instance_url and access_token that are required to then to execute a query and retrieve a response.

Many other things can be done with this powerful client – have fun!

For more information on our Server-Side Javascript SDK, see here.

For more information on Event Handlers on your backend, see here.

For more information on Server Extensions on your backend, see here.

Kevin

Contact