Rest message response.status

akin9
Tera Contributor

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

akin9_0-1675308956959.png

 

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);

4 REPLIES 4

akin9
Tera Contributor

Hello Experts,

Please support on this.

newhand
Mega Sage

@akin9 

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.) .

 

 

 

 

 

 

 

Please mark my answer as correct and helpful based on Impact.

akin9
Tera Contributor

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.

 

 

akin9_3-1675321801466.png

 

akin9_2-1675321725797.png

 

 

 

Please support to achieve. 

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.

 

 

Please mark my answer as correct and helpful based on Impact.