currently I am working on a simple service written in nodejs for RocketChat. But the module 'request' doesnt send my header parameters for authenticaton. Here are the details:

    url: rocketChatURL + '/api/v1/login', 
    method: 'POST',
    body: JSON.stringify({
        'user': rocketChatUser, 
        'password': rocketChatPass
    }, (err, res, body) => {
 if (err) { return console.log(err); }
 obj = JSON.parse(body);
 rocketChatAuthToken = JSON.stringify(;

//Channel Infos
var options = {
    url: rocketChatURL + '/api/v1/' + rocketChatRoom, 
    method: 'GET',
    //json: true,
    headers: {
        "X-User-Id": rocketChatUserID,
        "X-Auth-Token": rocketChatAuthToken,

Login returns the following object:

{ status: 'success',
   { userId: 'XYZ',
     authToken: 'JS_VNjOnFpicTIdhD4n1WOdvl950wOEa-LDDACqg_yN',
      { _id: 'XYZ',
        name: 'myTechuser',
        emails: [Array],
        status: 'online',
        statusConnection: 'online',
        username: 'myTechuser',
        utcOffset: 2,
        active: true,
        roles: [Array],
        settings: [Object],
        email: '[email protected]' 

First of all theres the login. Afterwards I want to get some channel information. Therefore the UserID and AuthToken have to be provided via header (see The response is always a HTTP 401 with the error message "You must be logged in to do this". After some research with 'request-debug' I saw that the request module just sends the "X-User-Id" Header but not the "X-Auth-Token" (see snippet below). This is the reason why the authentication fails. Because if I send the request manually via CURL (and of course with header parameters) the authentication works well.

Could you explain to my why the request-module doesnt send the second header option with the request?

{ request:
   { debugId: 3,
     method: 'GET',
      { 'X-User-Id': 'XYZ',
        host: '' } } }

{ response:
   { debugId: 3,
      { date: 'Mon, 29 Apr 2019 19:02:03 GMT',
        'content-type': 'application/json',
        'transfer-encoding': 'chunked',
        connection: 'close',
        server: 'nginx/1.13.12',
        'x-instance-id': 'g47SaWLkqdM2ZrhQ8',
        'access-control-allow-origin': '*',
        'cache-control': 'no-store',
        pragma: 'no-cache',
        vary: 'Accept-Encoding',
        'set-cookie': [Array],
        'strict-transport-security': 'max-age=31536000; includeSubDomains' },
     statusCode: 401,
      '{"status":"error","message":"You must be logged in to do this."}' } }

0 Answers