After scripts run once Postchi receives a response. They’re the right place to capture tokens, IDs, or any other value you want to reuse in later requests.Documentation Index
Fetch the complete documentation index at: https://docs.getpostchi.com/llms.txt
Use this file to discover all available pages before exploring further.
File naming
Place a file named<request-name>.after.js next to your request file:
after.js in that folder:
The request-level
<name>.after.js runs first, then the folder-level after.js. Both scripts can call setEnvironmentVariable and setSecret — all mutations from both are applied together.Available context
Postchi injects these variables into every after script:| Variable | Type | Description |
|---|---|---|
request | object | The final request that was sent (method, url, headers, body). |
response | object | The response received. |
env | object | All active environment variables as string key-value pairs. Read-only. |
fetch | function | The global fetch function. |
setEnvironmentVariable(key, value) | function | Saves a variable to the active environment in environments.cenv. |
setSecret(key, value) | function | Saves a secret to the active environment in secrets.cenv. |
The response object
| Property | Type | Description |
|---|---|---|
response.status | number | HTTP status code, e.g. 200 |
response.headers | object | Response headers as { name: value } pairs |
response.body | string | null | Response body as a string, or null |