Rest message and Mid server - 401 - Invalid username/password combo

jonay2
Mega Contributor

Hi,

I'm trying to connect to a third party with Rest Message and Basic Auth, but when I try to test the connection, the rest of the message returns a "401 - Invalid username / password combo" error, but if I go into the core server, I open a browser and put the end point in url and I put the user / end point returns a JSON.

My question is what am I doing wrong? Why on the server can I access the endpoint and from servicenow I don't have access? when I do a test on the rest message with the related link "Test", the response body returns 'You do not have permission to view this directory or page'.

find_real_file.png

The Http header and Http query is empty.

find_real_file.png

Also I have tried this:

https://community.servicenow.com/community?id=community_question&sys_id=29658baddbd8dbc01dcaf3231f961972&view_source=searchResult

find_real_file.png

And i have the same result.

Thanks,

Jonay

 

1 ACCEPTED SOLUTION

Hi,

The proble have been resolved with this workarround: https://hi.service-now.com/kb_view.do?sysparm_article=KB0778973

Thanks,

Jonay

View solution in original post

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

Not sure about the question. Is the question about getting authentication error when trying to connect to the third party on-premise service using a script generated by REST Message tool? There's no error when the service is accessed from ServiceNow web page?

If so, the most likely reason is MID server not being specified in the generated script. It's necessary to edit the following line in the generated script to specify the MID server to use.

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

 

Thanks for your answer.

No, the question is not how to get that error. I get that error when I launch a connection test from servicenow. But if I log into the server and open a browser if I get a JSON response.

Please provide the code that's generating the error. There's no error when logging into ServiceNow because the credentials are provided during the login.

The code probably isn't providing the correct credentials. Can't say where without looking at the code.

Hi,

Thanks for your answer.

The code it is OOTB:

var r = new sn_ws.RESTMessageV2('IN*****', 'getHardware*****');

//override authentication profile
//authentication type ='basic'/ 'oauth2'
r.setAuthenticationProfile('basic', 'd22f0797db42d4******0a1ca9619e6');

//set a MID server name if one wants to run the message on MID
r.setMIDServer('SNCSM*******');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.print(responseBody);

And the responsebody return  this:

find_real_file.png

But, if I enter to the server and open one navegator and go to the end point and put the auth basic and return with one file download with the JSON.