Pre-request Scripts
Overview
This document serves as a reference to the existing Pre-request Scripts file, which provides comprehensive information on pre-request scripts used in API Suite Execution.
Relevance to ISO Requests
Pre-request scripts are essential for ISO requests as they allow the retrieval of data from previously executed requests and update the current request's body accordingly.
Key Points for ISO Requests
- Use
fieldIdinstead ofpath/keyinpreReq.getBody()/req.setBody() - Requests must have unique labels in collection
Example (carry ISO fields from a previously executed ISO request):
In the script shown above, each field in the current request is populated using the value from the same field id in the previously executed Auth_0100 request:
req.setBody('3', preReq.getBody('Auth_0100', '3'));
req.setBody('4', preReq.getBody('Auth_0100', '4'));
req.setBody('7', preReq.getBody('Auth_0100', '7'));
req.setBody('11', preReq.getBody('Auth_0100', '11'));
...You can also use the Rules Snippets panel on the right to quickly insert helpers like UUID v4, UNIX Timestamp, ISO Timestamp, Random Alpha Numeric, Random Int, and more into your script.
For detailed methods and examples, please refer to the REST Pre-request Scripts for Suite Execution document.