0
votes

I'm trying to connect to the Salesforce SOAP API using JSForce

const connection = new jsforce.Connection({
  loginUrl: "https://customdomain.my.salesforce.com",
});
await connection.login(username, password);

When I run this I get the following error

Error: INVALID_LOGIN: Invalid username, password, security token; or user locked out.
    at /Users/juancaicedo/code/calm/salesforce-poc/node_modules/jsforce/lib/connection.js:1552:13
    at tryCallOne (/Users/juancaicedo/code/calm/salesforce-poc/node_modules/promise/lib/core.js:37:12)
    at /Users/juancaicedo/code/calm/salesforce-poc/node_modules/promise/lib/core.js:123:15
    at flush (/Users/juancaicedo/code/calm/salesforce-poc/node_modules/asap/raw.js:50:29)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
(Use `node --trace-warnings ...` to show where the warning was created)

Is this an okay way to authenticate, or should I do something else? I've seen mention of a security token elsewhere, is that preferred?

Notes

I'm able to log on to the Salesforce UI successfully using these credentials ✅

I would be open to using another Node.js library, but do need to use the SOAP API (using the REST API would not be sufficient).

2

2 Answers

1
votes

Some Salesforce orgs require the security token to be passed as well. You might find your token and try passing that in your API call.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_concepts_security.htm

1
votes

If you are using jsforce within salesforce, in that case, you can get a connection object directly by using the following snippet:

var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });

If you want to connect from the external system you can go with either of the ways:

  • Using Access Token and instance URL
  • Using username and password

specifying keys according to your respective library.

Note: If you are following username and password flow, in that case, you have to append a security token at the end of the password in order to achieve a successful authentication. You can get that security token by going to your user salesforce settings.

For node JS you can refer this package: https://www.npmjs.com/package/node-salesforce