Thread:Project:Support desk/API Create account doesn't work

Hi,

I've got some node.js code that makes a request to obtain a token and then makes a second request using a token but I get the same output as the first request - with just the token.

var token = "";

var data = querystring.stringify({       	action: "createaccount",        	name: "SeanTest",        	email: "xxx",        	password: "test",        	token: token,        	format: "xml"	    });

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);

var idxTokenStart = chunk.indexOf('token="');	           idxTokenStart = chunk.indexOf('"', idxTokenStart+1); idxTokenStart++;

var idxTokenEnd = chunk.indexOf('"', idxTokenStart);

token = chunk.substring(idxTokenStart, idxTokenEnd);

var mydata = querystring.stringify({		       	action: "createaccount",		        	name: "SeanTest",		        	email: "xxx",		        	password: "test",		        	token: token,		        	format: "xml"			    });

var myoptions = { 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(mydata) }	   		};

console.log("Data is: " + JSON.stringify(mydata));

var createReq = http.request(myoptions, function(createRes)	   		{			    	createRes.setEncoding('utf8');	        		createRes.on('data', function (chunk) { console.log("Data Body Is: " + JSON.stringify(chunk)); });	   		});

createReq.write(mydata); createReq.end; });	   });	    req.write(data); req.end; }

Any ideas?

Sean