This guide outlines how to add scripts at the flow level and the request level:
- Flow-level scripts apply to every request in the API test.
- Request-level scripts apply to an individual request.
In the API Test Editor, you can add two types of scripts at the flow-level:
- Flow-level pre-request scripts execute before every request in an API test.
- Flow-level post-request scripts execute after every response in an API test.
To add a flow-level script, click on the pencil icon in the flow title card to open the flow properties modal:
Accessing the flow properties modal
In the modal, you can select the Pre-request or Post-request tab and edit your script code as needed. Close the modal using the X icon when you are happy with the script.
Editing a flow-level post-request script
You can also add scripts for individual requests:
- Pre-request scripts execute code before a request is made.
- Post-request scripts execute code after a response is returned.
To add a pre-request script to an specific request, open the API Test Editor and take the following steps:
- Click on the test step you'd like to edit on the left-side panel.
- In the Request details section, select the Pre-request tab.
- Edit your script code as needed.
To add a post-request script to a specific request, open the API Test Editor and take the following steps:
- Click on the step you'd like to edit in the left-side panel.
- Open up the Validation and variable assignment section.
- Select the Script tab.
- Edit your post-request script as needed.
You can review pre-request and post-request scripts for individual steps on the test details page.