How to use response data from the the pre-request onto the same request

I have PUT request {{url}}/api/v1/users/{{userid}} but the userid variable it’s value I need it to come from a pre-request script response data the request is a GET request {{url}}/api/v1/users/search?query=muddu1&limit=1

Kindly note this is under one PUT request of {{url}}/api/v1/users/{{userid}}

Have you gone through the training yet as this covers basics like setting and retrieving variables and linking requests together.

Run through the “APIs 101 Training”, then the “Testing and Automation Training” course.

If you must have it as a pre-request script, then the GET request has to use sendRequest and you’ll need to get the element from the request and store it in a variable. (I would recommend environment or collection scope).

However, does it really need to be a pre-request script?
You could have a folder, with the GET request first, and the PUT request following.
You can then save the userid from the GET request response to a variable through the tests tab of that request which can be used in the following PUT request.

Hello @michaelderekjones,

Thanks for your help I finally got it working and the “APIs 101 Training” Helped however following your advice of using the GET request first then I use the PUT request in the TEST tab is also great but here is the simple Pre-request script that got it working as per my first request.

const getRequest = {
  url: 'https://{{url}}/api/v1/users/search?query={{userid}}&limit=1/get',
  method: 'GET',
  header: {
    'Content-Type': 'application/json',
    'X-Foo': 'bar',
    'Authorization': 'Basic xxxxxyyyyzzzzxxxxyy',
pm.sendRequest(getRequest, (error, response) => {
    let responseJson=response.json();