Closed bemau closed 8 years ago
Like all API calls, authenticate()
is asynchronous. Therefore that callback needs to happen before you call query()
. Try moving your query()
code inside of the callback for authenticate()
.
Also, you don't need to create a variable for oauth if you are using single user mode since the oauth credentials are cached inside of the connection object. You can completely omit that.
thanks @kevinohara80, works perfectly.
Having same issue with nforce node module for chatter feeds .
TypeError: Cannot read property 'instance_url' of undefined at Connection.getUrl (/home/ubuntu/workspace/node_modules/nforce/index.js:709:24) at get_feed (/home/ubuntu/workspace/components/chatter/middleware.js:70:19) at canvas_authentication (/home/ubuntu/workspace/components/chatter/middleware.js:82:7) at callbacks (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:164:37) at /home/ubuntu/workspace/components/organization/index.js:47:20 at Query.<anonymous> (/home/ubuntu/workspace/node_modules/mongoose/lib/model.js:4020:16) at /home/ubuntu/workspace/node_modules/kareem/index.js:273:21 at /home/ubuntu/workspace/node_modules/kareem/index.js:131:16 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9)
By calling this way...
Salesforce.getUrl('/services/data/v29.0'+OAuth.community+'/chatter/feeds/news/'+requestContext.userId+'/feed-items?pageSize=10', OAuth, function(err,resp){ if(!err) { sf_data = resp; render_response(); }else{ console.log('***error: ' + err); response.write(err); response.end(); } });
Hi Kevin,
Here is my code snippet through which i am trying to call an apex rest service and i get the error if(callback) callback(null, data); ^
TypeError: callback is not a function
`'use strict'
var nforce = require('nforce'); var query = 'SELECT Id, FirstName, LastName, Email FROM Lead LIMIT 10';
var oauth; var org = nforce.createConnection({ clientId: 'dfgdfgdfgfdgfd.2XjQ89MlDtOeYXx3SGF0VlfkRqjnYWRJUzj3rE54VhYWlfreMFlRODJIMlcWQ', clientSecret: 'dfgdfggdfgfd', redirectUri: 'http://localhost:3000/oauth/_callback', apiVersion: 'v34.0', environment: 'production', mode: 'single', autoRefresh: true });
org.authenticate({ username: 'gdfgdfgdfg', password: 'gddfgdf'}, function(err, resp) { if(err) { console.error('unable to authenticate to sfdc'); } else { oauth = resp;
org.query({ query: query, oauth: oauth }, function(err, resp) {
//if(err) throw err;
if(resp.records && resp.records.length) {
resp.records.forEach(function(rec) {
console.log('Lead: ' + rec.get('FirstName') + ' ' + rec.get('LastName'));
});
}
});
org.apexRest({uri:'/BlockList/', method: 'GET', urlParams: [{key:'keyWord', value:'hi'}]}, oauth, function(err, resp) {
//console.log(resp);
if(!err) {
console.log(resp);
//res.send(resp);
}else{
console.log(err);
//
//res.send(err);
}
});
} }); module.exports = org;`
Not sure what exactly is the issue, could you please suggest.
Thanks in adavance.
Regards, Bijay
Folks, any thought?
here the code