Use a value of an answer in other requests
A request can take a value from its answer and keep it in a variable: the token after signing in, or the identifier of what it made.
Keep the value
- Open the tab Checks of the request that gets the value.
- Under Keep in variables, press + Keep a value.
- On the left, write where the value is.
- On the right, write the name of the variable, without braces.
Each time you send the request and an answer comes, the variable has the new value. The tab Checks of the answer shows it under Kept in variables.
Say where the value is
| Write | To take |
|---|---|
token | That value of the JSON |
value.token | A value inside another |
items[0].id | The id of the first one of a list |
header:x-token | A header of the answer |
A value that is not in the answer changes nothing: the variable stays as it was.
Where it is kept
The value goes to the environment that you are using. If the variable is there, it keeps being secret or not, as you left it. If it is not, TotalAPI adds it, and makes it secret when its name has token, password, secret or key.
Any other new variable is written in the file of the collection. If the value is private, add the variable first and mark Secret.
An example
- The request Sign in keeps
value.tokenintoken. - The request My orders has
{{token}}as its Bearer token. - Send the first, then the second. When the token ends, send the first again.
It works also when you run the requests one after another.