List of users or export responses by token returns an empty response

More
4 months 2 weeks ago - 4 months 2 weeks ago #171823 by josoroma
josoroma created the topic: List of users or export responses by token returns an empty response
Hi!

I am trying to get a response from list_users method call just after getting a session key with get_session_key method call:

 
/* -------------------------------------------------------------------------------- */
 
// const request = require('request').defaults({ encoding: null });
const request = require('request');
const BufferList = require('bl');
const fs = require('fs');
 
let SESSIONKEY = '';
 
let options = {
  'url': 'http://localhost/index.php/admin/remotecontrol',
  'method': 'POST',
  'headers': {
    'user-agent': 'ZTT Agent 1.0',
    'host': 'localhost',
    'path': '/index.php/admin/remotecontrol',
    'connection': 'keep-alive',
    'content-type': 'application/json',
  }
};
 
/* -------------------------------------------------------------------------------- */
 
options.body = JSON.stringify({
  method: 'get_session_key',
  params: ['USERNAME', 'SECRET_BASTARD'],
  id: 2,
});
 
/* -------------------------------------------------------------------------------- */
 
const listUsers = (error, response, body) => {
  console.log('\n');
  // body = JSON.parse(body);
 
  console.log('(listUsers) - error ==>', error);
  console.log('(listUsers) - body ==>', body);
 
  if (!error && response.statusCode === 200) {
    console.log('(listUsers) - 200 ==>', 200);
  } else {
    console.log('(listUsers) - ERROR ==>', body);
  }
};
 
/* -------------------------------------------------------------------------------- */
 
exportResponsesByToken = (error, response, body) => {
  console.log('\n');
  console.log('(exportResponsesByToken) - error ==>', error);
  // console.log('(exportResponsesByToken) - response ==>', response);
  console.log('(exportResponsesByToken) - body ==>', body);
 
  console.log('(exportResponsesByToken) - new Buffer(body).toString()', new Buffer(body).toString());
 
  if (!error && response.statusCode === 200) {
    console.log('(exportResponsesByToken) - 200 ==>', body.result);
 
    // const buffer = Buffer.from(body, 'base64');
    // fs.writeFileSync('response.json', buffer);
  } else {
    console.log('(exportResponsesByToken) - ERROR ==>', body);
  }
};
 
const getSessionKeyCallback = (error, response, body) => {
  body = JSON.parse(body);
 
  if (!error && response.statusCode === 200) {
    if (SESSIONKEY === '') {
      SESSIONKEY = body.result;
      console.log('===> getSessionKeyCallback - 200 - SESSIONKEY', SESSIONKEY);
 
      // http://localhost/index.php/admin/tokens/sa/browse/surveyid/185897
      options.body = JSON.stringify({
        method: 'export_responses_by_token',
        params: [SESSIONKEY, 185897, 'json', 'UCsPViza6l6TvgP', 'en', 'all'],
      });
 
      console.log('===> options.body', options.body);
 
      request(options, exportResponsesByToken);
 
      // options.method = 'GET';
 
      options.body = JSON.stringify({
        method: 'list_users',
        params: [SESSIONKEY],
      });
 
      console.log('===> options.body', options.body);
 
      request(options, listUsers);
    }
  } else {
    console.log('getSessionKeyCallback - ERROR ==>', body);
  }
};
 
request(options, getSessionKeyCallback);
 
/* -------------------------------------------------------------------------------- */
 


...but body result response is empty, my current debugging outputs:




I am probably missing something.

Thanks!
Attachments:
Last Edit: 4 months 2 weeks ago by josoroma.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!