Scripts and chained requests
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
pass data from one response into the next request.
Planned topics
- A post-response script runs after a response arrives and can save values to variables.
- Typical chain: create a product, capture its ID, use
{{productId}}in the next requests. - The same works for tokens: log in, store the token, send it in
Authorization. - Add simple tests (status is
201, body hasid) so a run shows pass or fail. - Run the whole collection in order with the collection runner.
Draft outline details
Demonstration
const body = pm.response.json();
pm.environment.set("productId", body.id);
pm.test("created", () => pm.response.to.have.status(201));Check your understanding
How does request 2 get the ID created by request 1?
Show answer
Request 1 stores it in a variable.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.