Thread:Project:Support desk/node.js post request to mediawiki API

Hi,

I'm trying to post data to the mediawiki API and it's not recognising the token I am sending.

var data = querystring.stringify({             action: "createaccount",              name: "sean",              email: "xxx",              password: "test",              token: "66cde5ad831521fe9d0fe4df3a2db25f"        });

var options = { host: '54.201.91.132', port: 80, path: '/wiki/api.php', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(data) }       };

var req = http.request(options, function(res) {           res.setEncoding('utf8');            res.on('data', function (chunk) { console.log("body: " + chunk); });       });

req.write(data); req.end;

I have tried sending the same data using the Postman chrome extension and this works fine.

POST /wiki/api.php HTTP/1.1 Host: 54.201.91.132 Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded action=createaccount&name=shamus&email=xxx&password=test&token=5dc9c943ac3255f87dc7782c24f61ac6&format=json

{   "createaccount": { "username": "Shamus", "userid": 22, "token": "c3744c0f19ea62f6baf89b10f7c86f7f", "result": "success" }   }

Any ideas what I'm doing wrong?

Thanks,

Sean