How to make one API response, the request body of the other

Currently, I am facing a difficulty while using the POSTMAN. In my case, I need to make the response of one API to be used as the request body of the other API.

For Example:
There are two API. One is USER API and the other is ACCOUNT API. I want to create a user using POST /user and when I hit that I will get a user id in the response. I want that user id response to be use in my second API that is POST /account API to link that user to that specific account.

There are a lot of such interdependent APIs and I want that to be in a collection. So once I run the collection, the data generated automatically in the app for testing purposes.

Hey @avionics-astronomer :wave:

Welcome to the Postman Community! :postman:

You should be able to capture the response data that you require from the User API and store this in a variable. This variable can then be used in the Account API or anywhere else you need it.

An example of this workflow can be see here:

A basic example, if your response body looks like:

    "userId": 1234

In your Tests tab, you would store that value in a variable (Using various scopes):

pm.globals.set('userId', pm.response.json().userId);

In your second request, you can now use the {{userId}} variable syntax in the Params/Auth/Headers/Body/Etc to resolve the stored value.

1 Like

Thanks for your valuable reply to this topic and you time for providing me the solution. I will look into this and get back to you if needed.
Thanks again for such response.

1 Like

If you are new to Postman, then I would suggest a visit to the Learning Centre.

Overview | Postman Learning Center

Including the Postman Training links under “Other Resources”.


I would recommend the “Galaxy APIs 101” course first as it gets you used to the application features and the GUI.

Then the “Galaxy Testing and Automation” course which teaches you how to assert the responses. It includes defining and using variables from responses and should cover your use case.