2

I am querying data from the data base from salesforce and it is working find with jsforce -l http://test.salesforce.com I then do a .register and a .authorize and then I can pull data from my salesforce database with a query language, and It works great. My .jsforce/config.json looks like

{
    "connections": {
        "<my_username>": {
            "accessToken": "<my_accessToken>",
            "instanceUrl": "<https://my.partial.instance.com>",
            "client": "default"
        }
    },
    "clients": {
        "default": {
            "clientId": "<myclientid>",
            "clientSecret": "<longNumber>",
            "redirectUri": "https://localhost:1111",
            "loginUrl": "https://test.salesforce.com"
        }
    }
}

However I want to do this automatically using jsforce in javascript. Now i tried something like on the documentation for jsforce.

var jsforce = require('jsforce');
var conn = new jsforce.Connection({
  oauth2 : {
    // you can change loginUrl to connect to sandbox or prerelease env.
    loginUrl : 'https://test.salesforce.com',
    clientId : '<myclientid>',
    clientSecret : '<longNumber>',
    redirectUri : '<https://my.partial.instance.com>'
  }
});
conn.login(username, 'password'+'<clientSecret>', function(err, userInfo) {
  if (err) { return console.error(err); }
  // Now you can get the access token and instance URL information.
  // Save them to establish connection next time.
  console.log(conn.accessToken);
  console.log(conn.instanceUrl);
  // logged in user property
  console.log("User ID: " + userInfo.id);
  console.log("Org ID: " + userInfo.organizationId);
  // ...
});

ive also tried some thing like

var conn = new jsforce.Connection({
  oauth2 : {
    clientId : '<clientId>',
    clientSecret : '<clientSecret',
    redirectUri : 'https://localhost:1111'
  },
  instanceUrl : '<https://my.partial.instance.com>',
  accessToken : '<accessToken>'

});

and similar things from the website here they are all giving me { invalid_grant: authentication failure } which I belive mean that my authorization is invalid. What am I doing wrong my stuff is correct because it is working on the command line interface. thanks

Edit: I did all the slandered things like white list my ip and let users to self authorize bc again its working on the command line.

Vladimir_314159
  • 1,457
  • 1
  • 9
  • 21
  • So I found that I can use my file to sign in like [here](https://jsforce.github.io/blog/posts/20150816-jsforce15-released.html) however this still has me sign in and I want to have to do nothing. – Vladimir_314159 Jul 17 '18 at 15:31

0 Answers0