Send and receive a JSON request for a REST service

Relevant for: API testing only

The following tasks show how to send a single JSON request to a REST service method step (after it has been added to the canvas). To create a reusable model, create a prototype. For details, see Create a REST service model.

Note: If you are working with an API test created in UFT One 11.51 or earlier or Service Test 11.51 or earlier, you must expand the REST activity's wrapper and enter these properties in the HTTP Request step found inside the REST activity wrapper.

Set the HTTP properties

In the Properties pane's Input/Checkpoints tab , set the destination URL and the HTTP method, usually POST or PUT.

Back to top

Load the request body

  1. In the Properties pane, open the HTTP tab .

  2. Select Request Body type JSON.

  3. Click the Load JSON button and navigate to the .json file.

    Note: If your JSON file contains non-ASCII characters, you should save this file with UFT-8 encoding. Otherwise, the characters in your file may not display correctly in UFT One.

Back to top

Add a request header

If your server requires you to specify JSON during content negotiation, you need to set the request header.

  1. In the Properties pane, open the Input/Checkpoints tab .

  2. In the Input/Checkpoints tab, click the plus sign to add a RequestHeader array element.

  3. Add a custom request header named Accept with the value application/json.

Back to top

Modify the JSON body

Assign values to the JSON body

If you intend to dynamically assign values to the JSON body from a data source, you need to add escape characters.

In the Input/Checkpoints tab, in the Input area, display the Text view of the JSON body and add the escape character, \, for each occurrence of a square or curly bracket ({, }, [, and ]).

Do not use an escape character for link expressions enclosed by curly brackets. When no links are used, this is not required.

For example:

\{"results":  
\[
\{"name": "John", "id": 873829904, location: "NY"\},
\{"name": "Linda", "id": 726371109, location: "LA"\},
\{"name": "Mike", "id": 711029345, location: "NY"\},
\]  
\}

Include encrypted passwords in the JSON body

UFT One versions 2021 R1 and later:

To prevent sensitive data from being displayed in your test, test output, and test report, add encrypted passwords or encrypt plaintext passwords included in your request body.

Do the following:

  1. In the Text editor, put your cursor where you want to insert or highlight the password you want to encrypt, and then click Password. Alternatively, you can just click the corresponding input box in the Grid view, and then click Password.

  2. In the Input Password dialog box that opens, enter your plaintext password. UFT One automatically encrypts the password and inserts it into your request body.

Back to top