0

I am using a LWC Open source app to make a GET request to my Salesforce Org. I want to get the resource at : https://na111.salesforce.com/services/data/v42.0/sobjects/EventLogFile/0AT3h00000PE85uGAD/LogFile

The line with the callout:

conn.request('https://na111.salesforce.com/services/data/v42.0/sobjects/EventLogFile/0AT3h00000PE85uGAD/LogFile').then(response => {

But when I make the call, I get a TypeError stating:

TypeError: conn.request is not a function

conn is my Connection object variable.

The same conn variable works in a query earlier.

From the jsforce docs too, I see that the request is a valid function.

I'm new to node.js, so I maybe making some elementary mistake here.

Edit:

The full api.js that I am using:

    // Simple Express server setup to serve for local testing/dev API server
const compression = require('compression');
const helmet = require('helmet');
const express = require('express');
const jsforce = require('jsforce');
require('dotenv').config();
const { SF_USERNAME, SF_PASSWORD, SF_TOKEN, SF_LOGIN_URL } = process.env;
if (!(SF_USERNAME && SF_PASSWORD && SF_TOKEN && SF_LOGIN_URL)) {
    console.error(
        'Cannot start app: missing mandatory configuration. Check your .env file.'
    );
    process.exit(-1);
}
const conn = new jsforce.Connection({
    loginUrl: SF_LOGIN_URL
});
conn.login(SF_USERNAME, SF_PASSWORD + SF_TOKEN, err => {
    if (err) {
        console.error(err);
        process.exit(-1);
    }
});

const app = express();
app.use(helmet());
app.use(compression());

const HOST = process.env.API_HOST || 'localhost';
const PORT = process.env.API_PORT || 3002;



app.get('/api/sessions', (req, res) => {
        const soql = `SELECT Id, EventType, LogDate FROM EventLogFile LIMIT 10`;
        conn.query(soql, (err, result) => {
            if (err) {
                res.sendStatus(500);
            } else if (result.records.length === 0) {
                res.status(404).send('Session not found.');
            } else {
                const formattedData = result.records.map(sessionRecord => {
                    return {
                        id: sessionRecord.Id,
                        eventType: sessionRecord.EventType,
                        logDate: sessionRecord.LogDate
                    };
                });
                res.send({ data: formattedData });
            }
        });
});

app.listen(PORT, () =>
    console.log(
        `✅  API Server started: http://${HOST}:${PORT}/api/v1/endpoint`
    )
);

app.get(`/api/sessiondetails`, (req, res) => {
    console.log(conn);
     conn.request('https://na111.salesforce.com/services/data/v29.0/sobjects/EventLogFile/0AT3h00000PE85uGAD/LogFile').then(response => {
        console.log(response);
        console.log(response[0].ORGANIZATION_ID);
        let formattedData = {
            orgId: response[0].ORGANIZATION_ID
        }
        res.send({ data: formattedData });
     })
     .catch(function(err){
        console.log('error caught >>> '+err);
     });
});

/api/sessiondetails is where the issue is. Specifically the line with the call: conn.request('https:.....

Reference doc: http://jsforce.github.io/jsforce/doc/Connection.html Section: request(request, optionsopt, callbackopt)

Would appreciate any help!

3
  • Seeing your code helps, but I understand your confusion. It looks like it should work, as far as I can tell.
    – sfdcfox
    Commented Jul 16, 2020 at 14:54
  • 1
    Can you confirm you're getting connection successful with your login snippet(with some consoles, you will get an idea if it's logging to salesforce or not).
    – Ysr Shk
    Commented Jul 17, 2020 at 4:34
  • hi @Ysr Shk, yes. The login call works fine, I am even able to print out line under the module that is causing the error. console.log(conn) prints out correctly, but somehow fails in the GET request Commented Jul 17, 2020 at 5:04

0

You must log in to answer this question.