Make a request do more than it says on the tin
Plenty of API work is mechanical: attach a fresh token, stamp a timestamp, bump a page number, pull an ID out of one response so the next request can use it. Scripts turn that from manual work into something the request does for itself.
Run code before the request
Pre-request scripts have access to the request before it is sent, so they can modify headers, the body, query parameters, or the URL itself. A common pattern is auto-incrementing a page number:
rq.environment.set("page_number", rq.environment.get("page_number") + 1);
Every send now walks one page further through the endpoint.
Run code after the response
Post-response scripts run once you have a response. This is where assertions go, and where you capture values that later requests depend on — an access token, a newly created resource ID, a cursor for the next page.
Use the rq object
Both hooks share one runtime and one API surface. rq.request and rq.response expose the call itself; rq.environment, rq.globals and the other scopes let you read and write variables.






