Need to pass a data from a json response to the subsequent request's Post Body data however it is not working, something is going wrong - jmeter

I need to pass a data from a json response to the subsequent request's Post Body data however it is not working, something is going wrong.
First request returns the JSON in response body which looks like this:
"accessToken":[{"idToken":"eyJ05C3RU","token":"159c82d30ec3123e873ab989cc"}]
0000000
I have to extract 'accessToken' value to pass it to the next request's post bodydata (not under parameter tab of the request, it has to pass to BodyData tab of the next request)
I have created to JSON path extractors for the first request where getting response data with these values.
1JSON path extractor: $..accessToken[0].idToken
passed this in json path expression:$..accessToken[0].idToken
in the request of next request: { "idtoken": ${idToken}}
view results in tree:
shows post data as request:
POST data:{ "idtoken": ${idToken}}
response data:
omething broke!SyntaxError: Unexpected token $
at `Object.parse (native)`
Please help to resolve the issue. it will be really helpful.

Most likely your JSON Path expression is wrong or response isn't valid JSON.
You can fall back to Regular Expression Extractor which is not that handy, but will work for any text response, the relevant configuration would be:
Apply to: same as for JSON Path extractor
Reference name: idToken
Regular Expression: "idToken"\s?:\s?"(.+?)"
Template: $1$
Demo:
Reference material:
JSON Path Getting Started - if you want to continue with the JSON Path Extractor (double check that your response is a valid JSON using i.e. http://jsonlint.com/)
Using RegEx (Regular Expression Extractor) With JMeter - if you would like to go the regular expressions way

Thanks for all the help. I am able to overcome my issue by using JSON path expression extractor in the next request body as "idtoken": "${idToken_1}".

Related

Use of Json extractor

Im running a test plan containing 10 requests i need to get the variable value from 3rd response json to be passed to request URL of 10 th request passed . any way we can use json extractor to do this?
This can be accomplished by using any of the post processors for correlation in amongst any of the requests. I have shown an example below with JSON Extractor
Request Sample
The value that I am going to extract from 3rd request's response is "I am the value to be fetched from 3rd response"
JSON Extractor
I am using the below syntax in JSON Path Expression to extract data from "valueToBeFetched" json object and storing it in variable named "extractedValue_C"
$..valueToBeFetched
10th Request
Replacing the extracted value with syntax ${extractedValue_C} in 10th request
Output
Response Captured from 3rd Response
Captured value passed in 10th request
Hope this helps!
JSON Extractor obeys JMeter Scoping Rules so if you put it as a child of the 3rd request - it will be applied to 3rd request only.
If you come up with a valid JSONPath matching the value you want to extract - the value will be saved into a JMeter Variable which can be used anywhere after 3rd request (where it is defined or overwritten in next iteration)

Response Assertion / Regex Extractor Not Working in JMeter

I'm trying to extract the CSRF token so I can log in, and be able to obtain cookies, but I'm not able to.
I'm able to get a 200 response code when accessing the URL that contains the CSRF token, and I'm able to see it on the browser and the console, but my response assertion is not able to assert anything regardless of me changing the apply to, field to test, and pattern matching rules sections. My regular expression extractor isn't able to get anything either. All the headers to get to the URL are there. Any suggestions?
Forgot to mention, I'm able to get it on one server that's exactly (or should be) exactly the same as this one...
EDIT:
I placed it under the HTTP Sampler that has that response, and here is an example of what I get for my response assertion. I've also added various images.
Unfortunately you didn't share your output, so I cannot tell for sure, but although it seems your RegEx is correct in both cases, it could be that it doesn't match due to some extra spacing.
It appears that you are expecting a valid JSON, so instead of RegEx you could use JSON Extractor and/or JSON Assertion, for which extra spacing will not matter.
Example: if Response Data is
{"token":"12345"}
I can specify JSON Extractor as
(most important line is JSON Path: $.token)
and the result will be variable token with value 12345.
Here's a good online JSON Path tester, which can help you to figure out the right JSON Path.
If your goal is to check presence of a JSON Object with name of token and an arbitrary value I would recommend going for JSON Assertion instead.
Add JSON Assertion as a child of the request you would like to assert.
Use the following JSON Path query:
$.token
JSON Assertion is available since JMeter 4.0
If you still want to go for the Response Assertion - configure it as follows:
Pattern Matching Rules: Contains
Patterns to Test: {"token":"(.+?)"}

Extracting POST response data returns NOT_FOUND

I was hoping someone may be able to help with the following issue I have.
I have a 'HTTP Request' sampler that makes a POST request. The response data for this request as per the results tree is:
<script>window.document.location.href='handler.ashx?act=wzfin\x26req=nav\x26mop=requirements!new_finish_wiz\x26pk=0c86ea74-c067-4bcf-a49d-be7d0e420fbf';</script>
I want to grab the value for the pk parameter in the response URL above and store in a variable called REQUIREMENT_ID. I have set up a 'Regular Expression Extractor' for the sampler and set it up as per below:
Apply to: Main Sample Only
Field to Check: Response message
Reference Name: REQUIREMENT_ID
Regular Expression: (?<=pk=)(.*)(?=\')
Template: $1$
Match No: 1
Default Value: NOT_FOUND
However, when I run this, NOT_FOUND is being returned. Any ideas what I might be doing wrong?
`Regular Expression Extractor screenshot
Change your regular expression to this <script>.+pk=(.*?)'
And change your field to check to Body
Try this: ".pk=(.?)'"
Not to sure why you way doesn't work to be honest.

JMeter - JSON Extractor post-processor

I've been trying to figure out how to configure a simple JSON Path extractor (provided on jmeter-plugins) and where to put it (inside an Http sample, outside...)
As you can see, ${expiredaccesstokenerror} is empty.
In order to fill this variable, I'm trying to extract a vallue from body response:
As you can see I'm trying to extract from json body content like:
{
"error_description":"Access token expired",
"suberror":"expired_accesstoken",
"error":"invalid_grant"
}
So, I've set JSON extractor for extracting $.suberror, however, it's always empty.
${expiredaccesstokenerror} in sampler is trying to get variable before request or response. In post processor you set the variable expiredaccesstokenerror but it's too late for displaying.

JSON Path Extractor in JMeter

I am new to jmeter. Can anyone help me to use a response object of one request to be passed as a request header of next HTTP request ?
Let me explain.
I am getting an access token along with the response of login in my app:
{: "responseCode":18, : "message":"Successfully logged in.", : "responseObject":"8zWExE4eSdhcJDwnW9MgIw=="}
No I want to use this access token (8zWExE4eSdhcJDwnW9MgIw) as one of the parameter of next request.
I used JSON Path Extractor for this.But its not working.
I am using JSON Path Extractor as well and it works great if it is properly configured.
Just put it into request and fill fields:
Variable Name: access_token (or any other you want to use later in request like this ${access_token})
JSON Path: responseObject should be enough if the JSON you pasted is full response (thjose additional colons are just some mistakes when copy-pasting or the JSON is corrupted?)
Default Value: I always use some value like 'NotUpdated!' here so I can assert in the next step or at least see it easily in request.
Not seeing the full response it is quote hard to come up with a correct JSON Path expression.
Given what you posted it should be something like $.responseObject
See JSON Path Syntax guide for queries syntax examples and Using the XPath Extractor in JMeter (scroll down to "Parsing JSON") for plugin installation instructions and XPath to JSON syntax mapping.
Just in case anybody would face an issue with multiple variable extractions using JSON Extractor (like me), make sure to:
List the names of variables/path expressions/default values using a semicolon as a separator.
Provide default values for every variable.
The second point is apparently required, and I only found out about it from this
Medium post.

Resources