我正在尝试从节点连接salesforce api并使用nforce包。最初我已成功建立了oauth身份验证。在尝试与salesforce组件进行交互时,我在发送“/ account”路由请求时收到以下错误。任何人都可以帮助我。
/opt/test_node/node-sf-connection/node_modules/nforce/index.js:905 opts.oauth.instance_url, ^ TypeError:无法读取未定义的属性“instance_url” 在Connection._apiRequest(/opt/test_node/node-sf-connection/node_modules/nforce/index.js:905:17) 在Connection._queryHandler(/opt/test_node/node-sf-connection/node_modules/nforce/index.js:674:8) 在Connection.query(/opt/test_node/node-sf-connection/node_modules/nforce/index.js:618:15) 在/opt/test_node/node-sf-connection/server.js:51:11 at Object.resolve(/opt/test_node/node-sf-connection/node_modules/nforce/lib/promises.js:25:20) 在/opt/test_node/node-sf-connection/node_modules/nforce/index.js:301:16 at Object.resolve(/opt/test_node/node-sf-connection/node_modules/nforce/lib/promises.js:25:20) 在Request._callback(/opt/test_node/node-sf-connection/node_modules/nforce/index.js:863:23) 在Request.self.callback(/opt/test_node/node-sf-connection/node_modules/request/request.js:188:22) 在emitTwo(events.js:106:13) 在Request.emit(events.js:191:7) 在请求。 (/opt/test_node/node-sf-connection/node_modules/request/request.js:1171:10) 在emitOne(events.js:96:13) 在Request.emit(events.js:188:7) 在IncomingMessage。 (/opt/test_node/node-sf-connection/node_modules/request/request.js:1091:12) 在IncomingMessage.g(events.js:292:16)
请找到我尝试过的以下代码段。
var express = require('express');
var nforce = require('nforce');
var app = express();
app.use(bodyParser.json());
console.log("Trying to establish the connection");
var org = nforce.createConnection({
clientId : "################################",
clientSecret : "############################",
redirectUri : "https://login.salesforce.com/login/callback"
});
var oauth;
org.authenticate({ username: '!!!!!!!!!!!!', password: '!!!!!!!!!'}, function(err, resp){
console.log("authentication established");
// store the oauth object for this user
if(!err) {
oauth = resp;
console.log("Authentication established successfully");
console.log(oauth);
}else{
console.log(err);
}
});
var q = 'SELECT Id, Name FROM Account';
app.get('/account',function(req,res){
console.log("Fetching the account from salesforce");
org.query({ query: q }, function(err, resp){
if(!err && resp.records) {
console.log('It worked');
console.log("total : " + resp.totalSize);
console.log("fetched : " + resp.records.length);
var acc = resp.records[0];
acc.set('Name', 'Really Spiffy Cleaners');
acc.set('Industry', 'Cleaners');
org.update({ sobject: acc, oauth: oauth }, function(err, resp){
if(!err) console.log('It worked!');
});
}else{
console.log('error');
console.log(err);
}
});
});
var port = process.env.PORT || 3001; // set our port
console.log("Started");
app.listen(port);
console.log('port ' + port); // shoutout to the user