Skip to content

How do I read the Error message from the JSON Response for a REST Service

This example demonstrates how to Read an Error message from the JSON Response for a REST Service.

In this solution shown below, if you provide any invalid project name which does not exist in the Worksoft SaaS domain then it will through an error message which is captured using the "wsGetResponseErrorFields" command.

Solution:

# Command Target Value
Start of a web service block
1 wsBlockOpen

To set the Header Protocol
2 wsSetProtocol
REST
To set the URL for Triggering Runs Using Worksoft SaaS QaCONNECT REST API
3 wsSetRequestURL
https://www.web.worksoft.cloud/rest/v1/
${test_cycle_QaCONNECT_domain}/executions
URL
To set the type of request method to hit the appropriate service  
4 wsSetRequestMethod
POST

To set the authentication type - Basic
5 wsAuthenticationType Basic
To set the Username to login to Worksoft SaaS Domain
6 wsSetUsername
your user name
To Set the Password to login to Worksoft SaaS Domain
7 wsSetPassword your password
To set the request body format and output type
8 wsSetRequestHeaderParam Content-Type
application/json
Set the payload required for accessing the service
9 wsSetRequestPayload { "projectName": "YOUR_PROJECT_NAME", "annotationText":"YOUR_ANNOTATION_TEXT", "testCycleIdentifier": "YOUR_TEST_CYCLE_IDENTIFIER" }
Execute the Service Request
10 wsExecuteRequest
${URL}
Response
To get the response code
11 wsGetResponseErrorFields
<place_DataDefinitionName_here>
<place_DatasetName_here>
End of a web service Block
12 wsBlockEnd


Tips, Tricks, Gotchas & Best Practices:  

  • All the ws commands should be in between "wsBlockOpen" and "wsBlockEnd".
  • Authentication type should be given before username and password.
  • The "wsGetResponseErrorFields" command works only with REST services and not with SOAP services.


    Feedback and Knowledge Base