Possible to use curl upload an external json file instead of --data? - json

When testing a REST POST api via curl, is it possible to send data from an external json file, instead of inline via --data?

To specify the data from a file, use --data #filename. From man page of curl:
If you start the data with the letter #, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data #foobar.

Related

How to save response data in to CSV in Jmeter

I am trying to save Jmeter response in CSV file. I have tried some of the answers from StackOver Flow but those are not working.
Can anyone suggest me how can I achieve this?
Note: I have tried this and this.
Most probably it is something not feasible when it comes to CSV files as response data can have delimiter characters which will break your CSV file structure. For example if you use comma as delimiter and your response data contains commas - it will be not possible to save the response into a single CSV "cell".
If you need to save the response data I would recommend using XML format of the .jtl results file for this. You can amend JMeter's default result file configuration as follows:
Add next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
That's it, next time you run JMeter in command-line non-GUI mode as:
jmeter -n -t test.jmx -l result.xml
the result.xml file will contain the response data which can be examined using either View Results Tree listener or XML viewer/editor of your choice.
More information: How to Save Response Data in JMeter
If the response of your request can be stored in csv then you can use one of the following
'Save Responses to a file' in Listeners.
Capture the response using regular expression extractor and write the value to a file in Beanshell code.

How to save response data to CSV file that i am generating in Simple Data Writer in JMeter

I am executing one Thread Group which have multiple Http Request. And I am capturing the Error result into a CSV file using Simple Data Writer. But unable to add the response data to the same file. Can you guys please let me know how I can add the response data to this CSV file or is there any other way that we can use for this purpose?
Use simple data writer but change the option to produce XML. Remove CSV and select "Save as XML". There is a option to "Save Response Data(XML)" that is what you require as shown below.
Put the result file output format as ".jtl" and open it in the Excel to see the results.
You don't even need to Simple Data Writer for this, it can be done by amending JMeter Results File Configuration:
Add the next lines to user.properties file (lives in "bin" folder of your JMeter installation)
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data.on_error=true
Restart JMeter to pick the properties up
Next time when you run JMeter in command-line non-GUI mode like
jmeter -n -t test.jmx -l result.jtl
response data for failed samplers will be added to the results.jtl file, you will be able to inspect it using either View Results Tree listener or your favorite text/XML viewer/editor.

JMeter not reading variable from CSV file

I'm new to Jmeter and am trying to use variables from a CSV file in the path of my HTTP GET request.
I've looked through various tutorials and answers to this question, but I still can't figure out what I'm doing wrong. The file just has one header (ID). It works if I enter the ID in the path, but as soon as I try read it from the CSV file, it fails:
Your configuration looks good, double check jmeter.log file for any suspicious entries.
Other recommendations:
Given you have only a single column it might be easier to use __StringFromFile() function directly in the HTTP Request sampler body like:
/api/Users/${__StringFromFile(c:\Automation\Test.csv,,,)}
I believe Content-Type and Authorization should go in HTTP Header Manager, not in the request parameters
See Testing SOAP/REST Web Services Using JMeter article for more details.
The problem wasn't with the reading of the variable. I thought that the first line of the file would be treated as a header, but it reads the first line of the file as a variable, so my file looked like:
ID
001
It read "ID", when I wanted it read "001.

how to load .json file in elasticsearch

I have a .json file and I want to load into elastic search for filtering.
A simple way to get started is to use curl. If you have a JSON file with a single document, you could index it like this:
$ curl -XPOST "http://localhost:9200/example/default" -d#file.json
example is the index name and default the doc type.
For more information, take a look at the docs:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html

Upload Data in MapQuest DMv2 through CSV using Data Manager API call

I need to upload data in MapQuest DMv2 through a CSV file. After going through the documentation I found following syntax of uploading data-
http://www.mapquestapi.com/datamanager/v2/upload-data?key=[APPLICATION_KEY]&inFormat=json&json={"clientId": "[CLIENT_ID]","password": "[REGISTRY_PASSWORD]","tableName": "mqap.[CLIENT_ID]_[TABLENAME]","append":true,"rows":[[{"name":"[NAME]","value":"[VALUE]"},...],...]}
This is fair enough if I want to put individual rows in in rows[], but there is no mention of the procedure to follow to upload data through a CSV file. It has been clearly mentioned that "CSV, KML, and zipped Shapefile uploads are supported ". How can I achieve it though this Data Manager API service?
Use a multipart post to upload the csv instead of the rows. You can see it working here.
I used the CURL program to accomplish that. Here is an example of a CURL.exe command line. You can call it from a batch file, or in my case, from a C# program.
curl.exe -F clientId=XXXXX -F password=XXXXX -F tableName=mqap.XXXXX_xxxxx -F append=false --referer http://www.mapquest.com -F "file=#C:\\file.csv" "http://www.mapquestapi.com/datamanager/v2/upload-data?key=KEY&ambiguities=ignore"