Request JSON giving error in JMeter though works in postman - json

I am trying to do a load test for one of my APIs in JMeter. The API works fine when tested in swagger or in postman. It gives the correct result. However, when I am trying to call the same API in JMeter, it is throwing following error-
"errors":{"$.catIds[0]":["The JSON value could not be converted to System.Collections.Generic.List`]
Below is my request JSON (using the same in postman where it works perfectly)
{
"StdFilterParams": {
"name": "Anna",
"grade": "V",
"schedules": [
0
]
},
"SubList": {
"startTimes": [
"0"
],
"endTimes": [
"101010"
]
},
"catIds":
[
4001
]
}
Here, it doesn't allow me to run the request with this JSON with catIds =4001. My question is what is wrong with this request even if it works in postman.

Are you sure you're sending the same request in JMeter as in Postman?
For example there is a popular mistake that people forget to add Content-Type header via JMeter's HTTP Header Manager
In general if request works in Postman you can just record it using JMeter's HTTP(S) Test Script Recorder
Start HTTP(S) Test Script Recorder
If you're using HTTPS protocol - import JMeter's self-signed certificate into Postman
Configure Postman to use JMeter as the proxy
Run your request in Postman
JMeter will capture the request and generate the relevant HTTP Request sampler and the HTTP Header Manager
More information: How to Convert Your Postman API Tests to JMeter for Scaling

Related

How to send a GET request with JSON body in JMeter?

I am facing some issues as JMeter doesn't take the JSON body passed as a parameter. I tried through postman and it was working fine but for Jmeter it is not working
I am expecting a response from get request with JSON body in Jmeter
We're not telepathic enough in order to suggest you how you can fix your "some issues" without knowing the details of the "issues"
JMeter can send the GET request with the JSON (or any other) body
If the request works in Postman and doesn't in JMeter most probably you're not sending the same requests, the most common mistake is that people forget to add a HTTP Header Manager configured to send correct Content-Type header.
Just use a 3rd-party sniffer tool to intercept requests originating from JMeter or Postman, identify the difference(s) and amend your JMeter configuration so the requests would be exactly the same. Alternatively just record the request from Postman using JMeter's HTTP(S) Test Script Recorder

POST in JMeter gives "Unrecognized token 'json'"

I can not figure out why I get this error:
"Failed to parse request body as JSON resource. Error was: Failed to parse JSON encoded FHIR content: Unrecognized token 'json': was expecting ('true', 'false' or 'null')\n at [Source: UNKNOWN; line: 3, column: 29]"
FHIR is the standard used. I also tested with a valid JSON that worked with Postman, so I don't think the actual JSON is the issue.
I'm not sure if I'm correct, but it seems JMeter adds 'json' from somewhere as the error states the token 'json' is unexpected. This is the Request > Request body tab in View Results Tree.
This is just a test JSON, but I got the same response with a JSON body that is working in Postman (and I formatted correctly to be sure). I have the Content-Type header specified. I simply don't understand where the token 'json' would come from as my json itself doesn't contain the token. Does anybody know if JMeter adds something to the request?
You're sending incorrect payload, it should look like:
{
"test" : "X"
}
and you are sending
{
"test" : "X"
}json
^^^^ this guy is causing the issue
JMeter doesn't add anything to request, you need to double check your configuration, i.e. JMeter jmx scripts are "normal" XML files so you can use your favorite text editor to look up this json
If you're able to send a valid request using Postman you should be able to record it using JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy and run your request/collection - JMeter will capture the requests and generate relevant HTTP Request samplers which can be replayed successfully.
More information: How to Convert Your Postman API Tests to JMeter for Scaling
It happened to be that if you add a default parameter in an HTTP Request Defaults (in my case _format=json), it would add it to the body of the POST.
I fixed this by adding a BeanShell PreProcessor with the code:
if(sampler.getMethod().equalsIgnoreCase("get")){ sampler.addArgument("_format", "json"); }

Add a Key for Request Body in JMeter

I am running a Performance Test in JMeter
So in my case I need to give a Request Body as a Json String along with a key called 'json'
I cant find a way on JMeter to provide a key when passing the Request Body like Postman
ex : Key Value
json {some JSON String}
What I have tried in JMeter :
Postman API Call :
Just switch to "Parameters" tab where you will have Postman-like style definition of the request parameters in form of name-value pairs
Going forward, given you can successfully execute the request in Postman you should be able to record the request using JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy:
and if your request assumes test.pdf file upload make sure to copy this file to the "bin" folder of your JMeter installation

Format of JSON payload in Azure Logic App HTTP Request trigger

I have been trying to create a very simple Logic App in Azure but I keep failing because it does not seem to be accepting my JSON.
Using my payload
{
"userPrincipalName": "notmy#ddress.com",
"computerName": "MyComputername"
}
I created the trigger
I then use the values of my payload in my response:
Save it and then I POST using Hurl.it to the HTTP POST URL in the request.
So why the heck is the value not used? I'm not able to use any of the values I'm sending.
Okay.. that was dumb..
I had to add the Content-Type header to the POST:

JMeter to test java rest Api

How can i pass the json for post method if my json is like:
{
"REQUEST":{"REQUEST_BODY":{"Account_Name":"ak"}}
}
It gives me an error at time of parsing json value
In postman it run properly
In HTTP Request use Body Data tab and of course fill-in Server Name, Port Number, Path and Update Method if needed:
And under HTTP Request add a Header Manager:
And add to it required headers:
Note Content-type might be different for you.
If your request works in Postman you can just record it in JMeter:
Configure JMeter for recording, the fastest way is using JMeter Templates feature
From JMeter's main menu choose File - Templates - Recording - Create
Expand Workbench - HTTP(S) Test Script Recorder and click "Start
Configure Postman for recording. You can "tell" Postman which proxy server to use (JMeter in your case) via --proxy-server command-line argument
C:\Users\your_user_name\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
Execute your request in Postman
JMeter will capture the request and store it under Test Plan - Thread Group - Recording Controller
References:
Apache JMeter proxy Step-by-step
How to configure Postman Native Client App to use an external proxy