- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Developers!
I am using RestMessgev2 for sending a POST API request to a Third-Party API endpoint in a Scoped Application. I am able to successfully retrieve the response body when the HTTP Status Code is 200. However, I am receiving ClaimsService.getPrincipal() - Failed to fetch the user - 'ServiceNowTestUser' validation details
when the HTTP Status Code is 400,403 etc (Failed).
Code Snippet:
var restAPI = new sn_ws.RESTMessageV2('<REST MESSAGE v2 Object Name>', 'GENERATE_ACCESS_TOKEN');
var requestBody = "client_id=<CLIENT ID GOES HERE>" + "&client_secret=<CLIENT SECRET GOES HERE>" + "&username=ServiceNowTestUser" + "&password=<PASSWORD GOES HERE>" + "&grant_type=password";
It would be really great if you take a look at the issue and provide necessary resolution or workaround.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @Subramani3 ,
try to get the actual failure reason from the third party:
var restAPI = new sn_ws.RESTMessageV2('<REST MESSAGE v2 Object Name>', 'GENERATE_ACCESS_TOKEN');
var endPoint = restAPI.getEndpoint().replace('${baseUrl}', 'BASE URL GOES HERE');
restAPI.setEndpoint(endPoint);
var requestBody = "client_id=<CLIENT ID>" +
"&client_secret=<CLIENT SECRET>" +
"&username=ServiceNowTestUser" +
"&password=<PASSWORD>" +
"&grant_type=password";
restAPI.setRequestBody(requestBody);
try {
var response = restAPI.execute();
var statusCode = response.getStatusCode();
var responseBody = response.getBody();
if (statusCode == 200) {
gs.info("Success: " + responseBody);
} else {
gs.error("Third-party call failed. Status: " + statusCode +
" | Body: " + responseBody +
" | ErrorMsg: " + response.getErrorMessage());
}
} catch (ex) {
gs.error("RESTMessageV2 exception: " + ex.getMessage());
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
23m ago
okay, try opening the HTTP method, check Authentication type if it's set to Basic or OAuth 2.0, change it to No authentication.
also verify by navigating System Web Services > Outbound > REST Message Log, find the failed transaction, and check the raw response body SN actually received.
also if not getting results share the screenshots..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @Subramani3 ,
try to get the actual failure reason from the third party:
var restAPI = new sn_ws.RESTMessageV2('<REST MESSAGE v2 Object Name>', 'GENERATE_ACCESS_TOKEN');
var endPoint = restAPI.getEndpoint().replace('${baseUrl}', 'BASE URL GOES HERE');
restAPI.setEndpoint(endPoint);
var requestBody = "client_id=<CLIENT ID>" +
"&client_secret=<CLIENT SECRET>" +
"&username=ServiceNowTestUser" +
"&password=<PASSWORD>" +
"&grant_type=password";
restAPI.setRequestBody(requestBody);
try {
var response = restAPI.execute();
var statusCode = response.getStatusCode();
var responseBody = response.getBody();
if (statusCode == 200) {
gs.info("Success: " + responseBody);
} else {
gs.error("Third-party call failed. Status: " + statusCode +
" | Body: " + responseBody +
" | ErrorMsg: " + response.getErrorMessage());
}
} catch (ex) {
gs.error("RESTMessageV2 exception: " + ex.getMessage());
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Thank you so much for the reply. I am trying to get a 400 with an incorrect username and so that I can test the validation flow. I am not able to get the actual response which is sent by the API endpoint for 400.
When I try the API request in Postman with username incorrect intentionally then I am getting a 400 status code with the below details in the body. I am trying to retrieve the value in ServiceNow but unable to do so.
Method failed: (/AuthServices/Auth/connect/token) with code: 400
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
23m ago
okay, try opening the HTTP method, check Authentication type if it's set to Basic or OAuth 2.0, change it to No authentication.
also verify by navigating System Web Services > Outbound > REST Message Log, find the failed transaction, and check the raw response body SN actually received.
also if not getting results share the screenshots..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
13m ago
The Authentication was already set to "No Authentication" and I don't see anything the logs.