Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create User from Node.js Failure. #127

Open
monoto opened this issue Jun 8, 2020 · 3 comments
Open

Create User from Node.js Failure. #127

monoto opened this issue Jun 8, 2020 · 3 comments

Comments

@monoto
Copy link

monoto commented Jun 8, 2020

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.

@julianlam
Copy link
Member

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"

@monoto
Copy link
Author

monoto commented Jun 8, 2020

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.

@julianlam
Copy link
Member

Doesn't look like one of the write-api's errors, so I don't think it's us that's sending it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants