-
-
Save orlybg/79bd8e051d02e4d61cffe60fbd761bb0 to your computer and use it in GitHub Desktop.
Sample Node.js script using Restler for connecting to the new RESTful SugarCRM REST API in 6.7 and later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('util'), | |
rest = require('restler'); | |
var baseurl = "<<instance URL>>/rest/v10" | |
// get oAuth token | |
var jsonData = {"grant_type":"password","username":"<<username>>","password":"<<password>>","client_id":"sugar"}; | |
rest.postJson(baseurl+'/oauth2/token', jsonData).on('2XX', function(data) { | |
if ( data.error ) { | |
sys.puts("Error: " + data.error_message); | |
} | |
var token = data.access_token; | |
sys.puts('Success! OAuth token is ' + token); | |
// now with a token, make a call | |
rest.get(baseurl+"/me", { | |
headers: { "Content-Type" : "application/json", "OAuth-Token": token } | |
}).on('2XX', function(data) { | |
if ( data.error ) { | |
sys.puts("Error: " + data.error_message); | |
} | |
sys.puts(JSON.stringify(data)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment