How to chain together multiple requests
Written By Greg Schier
Last updated 3 months ago
When working with APIs, there are often dependencies between requests. For example, you might POST /users
to create a new user, then PATCH /users/<id>
to update the user's email address.
So how do you get the ID of the created user into the update? Request chaining is the way.
Just like how environment variables allow referencing values across requests, the new response(…)
function allows a request like PATCH /users/<id>
to directly reference the id
from the response body of POST /users
. Here's how.
Request Chaining Basics
Step 1 → Select the response()
function from the autocomplete menu (Ctrl+Space
) in any text field.
Step 2 → Once inserted, click the blue template tag to configure the function.
Step 3 → Select the request you want to reference.
Step 4 → Enter either JSONPath or XPath query to select just the value you want.
Step 5 → Send the request!
Sending the request will render the template and inject the referenced value -- just like using regular variables. If no response exists yet for that request, it will be sent automatically.
So why did this take a month to ship? Let's cover that now.
Multiple References Using Environments
What if you want to use the response()
tag from above in multiple requests? Simply define the tag in an environment variable and reference the variable multiple times.
And that’s it! Once you have the response tag defined as an environment variable, it can be used just like any other variable.