1

I'm using the request package to send a post request to get an authToken, and then a get request to get an array of parcel objects so I can send it on to the rest of my app. When I log the body.parcels, it shows me several [Object, Object] items. I can't see the data inside of these objects, so I'm having trouble figuring out what the data is.

var options = {
      uri: 'https://api.onetracker.app/auth/token',
      method: 'POST',
      json: {
        email: this.config.username,
        password: this.config.password,
      },
    };

    request(options, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        const authToken = body.session.token;

        const options = {
          uri: 'https://api.onetracker.app/parcels',
          method: 'GET',
          json: true,
          headers: {
            'x-api-token': authToken,
          },
        };

        request(options, function (error, response, body) {
          if (!error && response.statusCode == 200) {
            let result = body.parcels;

            console.log('Result: ' + result); // check

            this.sendSocketNotification('ONETRACKER_RESULT', result);
          }
        });
      }
Chris Shaugh
  • 185
  • 1
  • 1
  • 10
  • Does this answer your question? [How to print the full data coming in \[object Object\] in nodejs](https://stackoverflow.com/questions/61039233/how-to-print-the-full-data-coming-in-object-object-in-nodejs) – padaleiana Oct 08 '20 at 17:36

1 Answers1

4

You need to change your print line to:

console.log('Result: ', result); // check

See: How can I display a JavaScript object?

dwosk
  • 1,202
  • 8
  • 11