0

I'm getting an ECONNREFUSED error (shown below) when trying to make a POST request with the request module to my server's limesurvey remotecontrol API. Is there something I'm doing wrong? Code is below error.

Edit: fixed the space between the http: // now getting a new error.

New Error:

{"id":null,"result":null,"error":"unable to decode malformed json"}

Error:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

Code:

var options = {
    "url": "http://localhost/limesurvey/index.php/admin/remotecontrol",
    "headers": {
      "Host": "dev-rheumpro.cis.uab.edu",
      "Content-Type": "application/json",
      "Connection": "Keep-Alive",
      "Content-Length": "65",
      "Port": "80",
      "User-Agent": "request"
   },
   "body": '{ "method": "get_session_key", "params": { "username": "admin", "password":"password" },"id": 1}'
}

request.post("http: //localhost/limesurvey/index.php/admin/remotecontrol", options, function callback(error, response, body) {
if(!error && response.statusCode == 200){
    console.log("testing");
}
else {
    console.log(error);
}

});
yungStuck
  • 21
  • 5
  • maybe this just a typo only in the question, but just in case its also in your code: there is a space between 'http:' and '//' in request.post – balafi May 30 '14 at 20:43
  • Wow, I didn't even catch that thank you. I fixed it and now its giving me: '{"id":null,"result":null,"error":"unable to decode malformed json"}' @balafi – yungStuck May 30 '14 at 20:47
  • Where's your `jsonrpc` property in the JSON-RPC envelope? – David-SkyMesh May 31 '14 at 01:03
  • Does the server expect 'named' or 'positional' arguments (or perhaps either) in the `params` property of the JSON-RPC envelope? – David-SkyMesh May 31 '14 at 01:04
  • According to Limesurvey's API page its like jsonrpc 1 and they gave an example header that didn't have any mention of jsonrpc even though the site claims that what it uses. I used the Postman extension in Chrome to post to my server and it worked just fine. I am pretty new to this and I'm not sure if I am missing something in my code or something else. @David-SkyMesh – yungStuck Jun 02 '14 at 21:01
  • The body is exactly like the example they give you on their remote control API page. And it works in Postman so there must be something on my end that I'm not catching when I try to do it programmatically.@David-SkyMesh – yungStuck Jun 04 '14 at 14:20

1 Answers1

0

change 'id', 1 to ("your survey id").

jazeb007
  • 578
  • 1
  • 5
  • 11