Rest message response.status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 07:36 PM
Hello @ Ankur / Saurav11
Hello Exports,
we have created rest message for add the users on ADM group, our script is working fine for success.
but if users not added also we are getting the success.
how do i achieve this based on response.status.
if condition for respone. (response status" 0 " or response status message. for failure ).
below
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus == '200') {
workflow.scratchpad.responsestatus = 'success';
workflow.scratchpad.response = ' Access granted';
}
else {
workflow.scratchpad.responsestatus = 'failed';
workflow.scratchpad.response = 'Failed to add. Below is the response. \n'+JSON.stringify(responseBody);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 10:27 PM
Hello Experts,
Please support on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 10:32 PM - edited 02-01-2023 10:38 PM
http-status is a server level resutl , and acturly you also need to handle the business level result from the response body.
When http stuts is 200, get the real status from response body and use this status to judge "success" or "failed".
And when the http status is not 200 , generally it may means "failed" (not 100% ,you need to have a further judge according to the target api's documents.) .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 11:10 PM
Hello @newhand.
Thank you for your quick reply and clarification .
Requirment -1
our case if server reached to ADM+ its taking as success.
issue is if user not added on the group also its taking as success.
how we can set failed if user not added on the group or group not found.
Requirment -2
and we have tried to create a rest message for Search Group on ADM+
but its getting method failed can you please support.
Please support to achieve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 05:57 PM
HI @akin9
It seems you are using serviceNow to call a 3rd part api .
Requirment -1
our case if server reached to ADM+ its taking as success.
issue is if user not added on the group also its taking as success.
how we can set failed if user not added on the group or group not found.
⇒ As i posted yesterday
1. judge the http-status (generally 2xx or not )
Below is international standard ,but not everyone adheres to this standard,so follow the api document !
- 1xx informational response – the request was received, continuing process
- 2xx successful – the request was successfully received, understood, and accepted
- 3xx redirection – further action needs to be taken in order to complete the request
- 4xx client error – the request contains bad syntax or cannot be fulfilled
- 5xx server error – the server failed to fulfil an apparently valid request
2. if the step1's result is success ,then get the response body (it's a json from you pic)
3. get the "status" field from the json and judge if successful or fail ( 1 or other ? following the api document ! )
Requirment -2
and we have tried to create a rest message for Search Group on ADM+
but its getting method failed can you please support.
⇒ From your pic, i can see the http-status is 404 ,it meams the api you are calling doesn't exist.
Check the url first.