JMeter: failed POST method (JSON body and filtering in path) - json

I'm trying (without success) to create data in JMeter (POST method) using JSON body data and only one way of access through API: access key (no login credentials or other details for server).
The access key only works in PATH (tried in header, no luck) and besides that, filters are required in path to call the exact services I need (please see screenshot 1)
Here are a couple of screenshots (data was edited, sensitive info)
1
HTTP Request
2
Header Manager
In Results Tree I get 301 Moved Permanently.
Is there a way to add those filters, keep the JSON body data + access token in path and get a 200/201 Created? :)

Found the issue for "301 Moved Permanently" after Post method was used:
Should have specified in Protocol "https" not http :(

Related

Issue while upload/send file with post request using Jmeter

I have one post request where I am uploading image as per below using postman :
I am trying to perform same request using Jmeter. I did following setting in Jmeter :
But somehow it is not working. I tried with multipart/form-data for POST option also but no luck.
our API developer has set validation that if api get any other file then image then they send response : invalid file type. I am getting this response all time when do POST request with image from Jmeter. It works fine with postman.
In Debugger post processor it shows like this : HTTPsampler.Files=path:'C:\apache-jmeter-4.0\bin\samplex.png'|param:'fileName'|mimetype:'image/png'
Finally I was able to resolve issue by removing Parameter name and MIME Type from tab File Upload. I did provide only file path and it works. Also I unchecked Use multipart/form-data for POST
You see button Browse.. in picture 2 you post. Do for same with Postman, choose file and send the request.
Make sure you have a valid file at the specified path.
Check your postman whether it is sending any other things in the header like Content-Type.
Check out File Uploads using JMeter guide for more information on simulating file uploads with JMeter
As I wrote in comment, If you want to send binary file as is (not as parameter value), remove the Parameter Name column value (file)
See JMeter's HTTP Request reference for more details:
File Path: Name of the file to send. If left blank, JMeter does not send a file, if filled in, JMeter automatically sends the request as a multipart form request.
If it is a POST or PUT or PATCH request and there is a single file whose 'Parameter name' attribute (below) is omitted, then the file is sent as the entire body of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests, and also for PUT requests.

How to use JSON variable of GET request in other HTTP request?

I'm really new in JMeter.
Tenant has Multple Environments
I have a test plan to create a Tenant, Get the tenant list. And then i have a JSON Extractor to save the Tenantid in order to create automatly an Environment in the desired tenant.
JSON Extractor:
then I set a Header manager to use the ID of this tenant to create the Environment in the Tenant
My HTTP request is set like this
[enter image description here][3]
But it doesn't work. Can you point me what i'm doing wrong?
Double check that your JSON Extractor works via Debug Sampler and View Results Tree listener combination. You should see tenantId variable value there. See How to Debug your Apache JMeter Script article for more details.
If you really need to send PATH HTTP Header make HTTP Header Manager a child of the next HTTP Request sampler to avoid any clash with other HTTP Header Manager instances. Mind that URL Path is not the same as HTTP Header named PATH
Check jmeter.log file for any suspicious entries.

How to use responses from a Jmeter JDBC Request in a HTTP Request

Here's my situation:
I want to do this:
I have a list of URLs in a MySQL database which I want to hit using a HTTP Request to see if the response is a HTTP Status code of 404 or not.
I have done this:
Added and configured a JDBC Config Element.
Added and configured a JDBC Request Sampler. Basically a select statement that returns a table with 8 columns. I have provided 8 comma-separated variables for the 'Variable names' field, so that the results of the JDBC request can be identified with these variable names.
Created a HTTP Request Sampler that uses one of those variables ${url} in the 'Server Name or IP' field.
Though the JDBC request works flawlessly and returns a table with a bunch of rows, the problem with this is that the HTTP Request Sampler never picks up the variable from the JDBC Request result.
The HTTP Request looks like this in the 'View Results Tree':
GET http://${url}/
I have tried these solutions:
Add 'Save Responses to a File' listener to the JDBC Request. This creates a file of type '.plain' and not a CSV. Had it been a CSV, I could have utilized that CSV file by creating a CSV Data Set Config. So this attempt failed.
I have tried forcing the file name in the above attempt to always use 'C:\JMETERTest\data.csv'. But it ends up creating a new file named 'C:\JMETERTest\data.csv1.plain'. This attempt failed too.
I tried to reference the URL column as ${url_1} in the HTTP Request's Server Name field. It worked. But the problem now is that in the results tree, all the requests are going for the the URL from only the first row of the result set. I see that this is because of the row number '_1' specified in the ${url_1} above. I can use this if someone can suggest a way to parameterize the '_1' into a variable that I can loop through (probably using a 'Counter' element). I created a Counter Config Element by the Reference Name 'loopCounter'. And used this in the Server Name field of the HTTP Request:
${url_("${loopCounter}")}
But now my HTTP Requests look lamer:
GET http://${url_("${loopCounter}")}/
This did not work too.
Solution 3 looks more doable to be only if I could resolve the parameterization of the row number.
I am open to JMeter Plugin suggestions too.
I will update anything else that I try as we go on.
P.S. Please let me know if my question is not clear in anyway.
Have you tried wrapping the HTTP sampler in a ForEach controller (parent) where the variable for the controller is the URL variable obtained from the JDBC sampler?
Also, the output variable in the ForEach will be the variable you now use in the HTTP sampler.
That way it will iterate through each variable from the beginning of the index to the end and run the sampler once each time.
In 'Save responses to a File' Listener, Select Checkboxes "Don't add Suffix and Prefix". Checking these two options will ensure, you get exact Log file name.

How to add 'Access-Control-Allow-Origin' to JSON endpoint

The phrasing of this questions is probably indicative of naivety but as I understand JSON endpoints, they are a URL I can point to to grab JSON objects.
This error seems to indicate though that not all urls are the same. I've tried multiple methods of mocking a remote JSON endpoint:
1) I've used mockable.io which gives me a link. I can GET with that link but POST or a GET gets me an Access-Control error.
2) I've tried pointing to a local json file. I can GET with this but POST or GET throws a 501 not implemented error.
3) I tried hosting the folder locally then opening that port globally with ngrok so that any computer in the world can access the json file with ngrok391.whatever.com. This throws the Access-Control error even for a GET.
The only other time I've seen this error was with a different setup, tomcat and java. A friend did the backend mostly so I don't remember the specifics but we basically found a line somewhere and added Access-Control-Allow-Origin: *.
What is the relevant "thing" to do for what I'm trying to do now. Not sure what to call this "thing", possibilities include "allow cross-domain data access", "add a header to a json file" (w/e that means), or "easily get and post to a data file"

Nginx return an empty json object with fake 200 status code

We've got an API running on Nginx, supposed to return JSON objects. This server has a lot of load so we did a lot of performance improvements.
The API recieves an ID from the client. The server has a bunch of files representing these IDs. So if the ID is found as a file, the contents of that file (Which is JSON) will be returned by the backend. If the file does not exists, no backend is called, Nginx simple sends a 404 for that, so we save performance (No backend system has to run).
Now we stumbled upon a problem. Due to old systems we still have to support, we cannot hand out a 404 page for clients as this will cause problems. What I came up with, is to return an empty JSON string instead ({}) with a 'fake' 200 status code. This needs to be a highly performant solution to still be able to handle all the load.
Is this possible to do, and if so, how?
error_page 404 =200 #empty_json;
location #empty_json {
return 200 "{}";
}
Reference:
http://nginx.org/r/error_page
http://nginx.org/r/return
http://nginx.org/r/location
You can always create a file in your document root called e.g. empty.json which only contains an empty object {}
Then in your nginx configuration add this line in your location block
try_files $uri /empty.json;
( read more about try_files )
This will check if the file requested by the client exists and if it does not exist it just shows empty.json instead. This produces a 200 HTTP OK and shows a {} to the requesting client.