How to chain requests using Insomnia (get token from login api to use as header for other api)

In your workspace press CTRL+E to open “Manage Environments” window

Add a variable like “token” to the environment
enter image description here

Put a response function (teal f) as value of this variable by pressing CTRL+SPACE.
Select one to your liking from the dropdown, in your case “Response => Body Attribute” should work well.

This will open a “Tag” form, like this one:
enter image description here

Select your login request and filter the response json or xml for the value containing your token value, f.e. $.access_token. Probably set trigger behaviour to “When Expired” too.

You can now access this variable anywhere in your workspace for other requests by pressing CTRL+SPACE in any form field and selecting the variable (purple x).

If you only need this for one request, you can skip setting up the environment variable for this and directly put the function where you need it, same way as described before.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)