0

I am using JMeter's JSON extractor to pass a variable id from one request to another.

This is the response of the first request (https://reqres.in/api/users?page=2):

{
  "page": 2,
  "per_page": 6,
  "total": 12,
  "total_pages": 2,
  "data": [
    {
      "id": 7,
      "email": "[email protected]",
      "first_name": "Michael",
      "last_name": "Lawson",
      "avatar": "https://reqres.in/img/faces/7-image.jpg"
    },
    {
      "id": 8,
      "email": "[email protected]",
      "first_name": "Lindsay",
      "last_name": "Ferguson",
      "avatar": "https://reqres.in/img/faces/8-image.jpg"
    },
    {
      "id": 9,
      "email": "[email protected]",
      "first_name": "Tobias",
      "last_name": "Funke",
      "avatar": "https://reqres.in/img/faces/9-image.jpg"
    },
    {
      "id": 10,
      "email": "[email protected]",
      "first_name": "Byron",
      "last_name": "Fields",
      "avatar": "https://reqres.in/img/faces/10-image.jpg"
    },
    {
      "id": 11,
      "email": "[email protected]",
      "first_name": "George",
      "last_name": "Edwards",
      "avatar": "https://reqres.in/img/faces/11-image.jpg"
    },
    {
      "id": 12,
      "email": "[email protected]",
      "first_name": "Rachel",
      "last_name": "Howell",
      "avatar": "https://reqres.in/img/faces/12-image.jpg"
    }
  ],
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}

In the extractor I named the variable userID and JSON path $..id match no. (1) and default value NoIDFound main sample only I'm also using a debug sampler and it passes with no problem Now I'm passing the variable in the second request as (https://reqres.in/api/${userID})

I'm getting 404 Not Found and the request that passed is (https://reqres.in/api/users/NoIDFound)

Can someone tell what i'm doing wrong?

1 Answer 1

1

It's hard to say anything without seeing your Test Plan, I have one assumption, your JSON Extractor might be incorrectly placed. See JMeter Scoping Rules user manual chapter for more information

So if you have the following setup:

enter image description here

it means that the JSON Extractor will be executed after each Sampler, after HTTP Request 1 it will have correct anticipated value and after Debug Sampler it will not because the JSONPath expression won't match anything and you will end up with the default value.

So make the JSON Extractor a child of the HTTP Request 1

enter image description here

Or use Debug PostProcessor instead of Debug Sampler

More information: How to Use the JSON Extractor For Testing

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that was the problem. I had the extractor as a child of the thread group instead of the request. When I moved it under it, it worked fine. thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.