Query to Salesforce using Jsforce nodejs package loads infinitely leading to a request abortion

184 Views Asked by At

I'm trying to fetch data from salesforce using jsforce npm package but the request just keeps loading. I'm using the Username and Password Login (OAuth2 Resource Owner Password Credential) auth method; the authentication flow returns the access_token and instance url but the actual query loads infinitely.

Here is the simple nodejs app code I've tried

import express from 'express';
import jsforce from 'jsforce';
import dotenv from 'dotenv';
dotenv.config();

const app = express();
const port = 3000;

let conn = new jsforce.Connection({
    oauth2 : {
        clientId: process.env.SF_CLIENT_ID,
        clientSecret: process.env.SF_CLIENT_SECRET,
        redirectUri: process.env.SF_REDIRECT_URI,
        loginUrl: process.env.SF_LOGIN_URL
    },
    loginUrl : process.env.SF_LOGIN_URL
});

conn.login(process.env.SF_USERNAME, process.env.SF_PASSWORD, (err, userInfo) => {
    if (err) {
        return console.error("This error is from the login attempt: ", err);
    }
    console.log(`Access Token: ${conn.accessToken}`);
    console.log(`Instance URL: ${conn.instanceUrl}`);
    console.log(`User ID: ${userInfo.id}`);
    console.log(`Org ID: ${userInfo.organizationId}`);
});

app.get('/cases', (req, res) => {
    conn.query("SELECT Id, CaseNumber FROM Case", (err, result) => {
        if (err) {
            return console.error(err);
        }
        console.log(`total : ${result.totalSize}`);
        console.log(`fetched : ${result.records.length}`);
        res.send(result.records);
    });
});

app.listen(port, () => {
    console.log(`App listening at http://localhost:${port}`);
});

I was expecting the the /cases endpoint to return the list of cases when I send a request to http://localhost:3000

0

There are 0 best solutions below