Required HTTP authorization header malformed: 'Bearer'

Community Alums
Not applicable

Hi,

Instance successfully issues OAuth token to a client application. However, subsequent REST API call made to ServiceNow with the token fails. Node log file indicates that authorization failed. Reason is listed as "Required HTTP authorization header malformed: 'Bearer'.

I've tested the integration with POSTMAN and it works fine.

Please let me know what might be causing this error.

2 REPLIES 2

Kajal Goti
Mega Guru

Hi

As per my understanding you have wrote scripted Rest for fetching authentication token 

 

when you are hit API for Auth token from Postmen It's work,but givining error from scripting

 

Have you checked all headers and all parameter which are neccessary in code

Putting sample code for auth token generation script


var rest_msg = new sn_ws.RESTMessageV2();
rest_msg.setRequestHeader("Content-Type", "application/json");
rest_msg.setEndpoint(Endpoint);  //Set  target URL
rest_msg.setHttpMethod('POST'); //Method


var responseJSON = {}; //Prepared request body,I.E Credentials for target API to be hit(Username and Password)
var email = 'abc';
var pwd = '123';
responseJSON.email = email.toString();
responseJSON.password = pwd.toString();
rest_msg.setRequestBody(JSON.stringify(responseJSON));
var response = rest_msg.execute();
var tokenDetails = response.getBody();
var finalToken= JSON.parse(tokenDetails);

gs.info(finalToken.token);//Fetch exact value form Json repsonse for token
},

 

Please mark as Correct/Helpful,If you find any help worthy

 

Let me know,If you need further help

Can you please mark this to Correct, If it's worked for you

 

So in future this thread will help to other's to solve the issues