- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 06:48 AM
I have a response from target system and need to fetch the status from it and it seems to contain a lot of u0022 in it . How can I fetch the status and its values from the below payload.
{"attributes":{"appType":"Connected","message":"Failed to get server response. Response returned: {\u0022type\u0022:\u0022error\u0022,\u0022status\u0022:409,\u0022code\u0022:\u0022user_login_already_used\u0022,\u0022help_url\u0022:\u0022http:\\/\\/developers.box.com\\/docs\\/#errors\u0022,\u0022message\u0022:\u0022User with the specified login already exists\u0022,\u0022request_id\u0022:\u001340hfdcheqmi8u4fk\u0022}"},"complete":false,"errors":["Status : failed\nAn unexpected error occurred: appname.tools.GeneralException: The application script threw an exception: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1 BSF info: script at line: 0 column: columnNo\n"],"failure":false,"metaData":null,"requestID":null,"retry":false,"retryWait":0,"status":null,"success":false,"warnings":null}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 07:19 AM
Hi @Kumar38 ,
Please try -
var obj = {"attributes":{"appType":"Connected","message":"Failed to get server response. Response returned: {\u0022type\u0022:\u0022error\u0022,\u0022status\u0022:409,\u0022code\u0022:\u0022user_login_already_used\u0022,\u0022help_url\u0022:\u0022http:\\/\\/developers.box.com\\/docs\\/#errors\u0022,\u0022message\u0022:\u0022User with the specified login already exists\u0022,\u0022request_id\u0022:\u001340hfdcheqmi8u4fk\u0022}"},"complete":false,"errors":["Status : failed\nAn unexpected error occurred: appname.tools.GeneralException: The application script threw an exception: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1 BSF info: script at line: 0 column: columnNo\n"],"failure":false,"metaData":null,"requestID":null,"retry":false,"retryWait":0,"status":null,"success":false,"warnings":null};
//var jsonobj = JSON.parse(obj);
var split = obj["attributes"]["message"].split('"status":')[1];
var status = split.split(",")[0];
gs.info(status)
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 07:19 AM
Hi @Kumar38 ,
Please try -
var obj = {"attributes":{"appType":"Connected","message":"Failed to get server response. Response returned: {\u0022type\u0022:\u0022error\u0022,\u0022status\u0022:409,\u0022code\u0022:\u0022user_login_already_used\u0022,\u0022help_url\u0022:\u0022http:\\/\\/developers.box.com\\/docs\\/#errors\u0022,\u0022message\u0022:\u0022User with the specified login already exists\u0022,\u0022request_id\u0022:\u001340hfdcheqmi8u4fk\u0022}"},"complete":false,"errors":["Status : failed\nAn unexpected error occurred: appname.tools.GeneralException: The application script threw an exception: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1 BSF info: script at line: 0 column: columnNo\n"],"failure":false,"metaData":null,"requestID":null,"retry":false,"retryWait":0,"status":null,"success":false,"warnings":null};
//var jsonobj = JSON.parse(obj);
var split = obj["attributes"]["message"].split('"status":')[1];
var status = split.split(",")[0];
gs.info(status)
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 07:26 AM
Hi @Kumar38
You can use below code to get the status
var responseStr=JSON.stringify({"attributes":{"appType":"Connected","message":"Failed to get server response. Response returned: {\u0022type\u0022:\u0022error\u0022,\u0022status\u0022:409,\u0022code\u0022:\u0022user_login_already_used\u0022,\u0022help_url\u0022:\u0022http:\\/\\/developers.box.com\\/docs\\/#errors\u0022,\u0022message\u0022:\u0022User with the specified login already exists\u0022,\u0022request_id\u0022:\u001340hfdcheqmi8u4fk\u0022}"},"complete":false,"errors":["Status : failed\nAn unexpected error occurred: appname.tools.GeneralException: The application script threw an exception: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1 BSF info: script at line: 0 column: columnNo\n"],"failure":false,"metaData":null,"requestID":null,"retry":false,"retryWait":0,"status":null,"success":false,"warnings":null});
var formattedResponse=JSON.parse(responseStr);
gs.print(formattedResponse.status);