nodebb-plugin-write-api
nodebb-plugin-write-api copied to clipboard
Create User from Node.js Failure.
nodebb version 1.13.2 nodebb-plugin-write-api version 5.7.3 node.js version 12.14.1
post data:
username=Panama.City&password=12345678&email=panama.city%40domain.com
http request option:
{ hostname: 'localhost',
port: 4567,
path: '/api/v2/users',
method: 'POST',
timeout: 5000,
headers:
{ Authorization: 'Bearer <token>' } }
var req = require('http').request(options, (res) => {
let data = '';
// A chunk of data has been recieved.
res.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
res.on('end', () => {
console.log(data);
var rt = JSON.parse(data);
if (callback) callback({status: 'success'});
});
req.on('error', (e) => {
if (callback) callback({status: 'failure'});
});
});
req.write(postData);
req.end();
Error: "value" required in setHeader("accessToken", value)
at validateHeader (_http_outgoing.js:492:11)
at ClientRequest.setHeader (_http_outgoing.js:501:3)
at new ClientRequest (_http_client.js:173:14)
at Object.request (http.js:38:10)
Any idea what I did wrong there? Thank you for an excellent plugin to an excellent forum platform.
To preclude an error with write-api, please try doing the request via cURL:
curl -H "Authorization: Bearer <token>" -X POST localhost:4567/api/v2/users --data "username=Panama.City&password=12345678&email=panama.city%40domain.com"
curl command did work. but it returns {"error": "Invalid Access Token"} and created the user account anyway. I am on amazon EC2 cloud... error could be from the server.
Doesn't look like one of the write-api's errors, so I don't think it's us that's sending it...