How to place comments in Postman? - comments

How to place comments inside Postman? Specifically in the JSON request body section?
I want to comment-out a particular key or value from the request body so that it is not sent.
Commenting out a JSON key/value pair with // or /* ... */ appears as a styled comment inside Postman:
But sending this request results in server errors such as the below, and it's clear that the commented-out line is being sent as part of the request body:
Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 2, column: 6
]
The JSON spec does not allow comments: Can comments be used in JSON?
I want Postman to strip the commented lines prior to being sent in the request.

You can write documentation and comments using the description section of the requests, collections or folders.

Finally, since Postman v8.3.0 you can do this in your collections pre-request script:
// Strip JSON Comments
if (pm?.request?.body?.options?.raw?.language === 'json') {
const rawData = pm.request.body.toString();
const strippedData = rawData.replace(
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
(m, g) => g ? "" : m
);
pm.request.body.update(JSON.stringify(JSON.parse(strippedData)));
}
This strips all comments from the json and sets the current body to the cleaned one, there are more examples for other body types (GraphQL, URL Encoded, Form Data) in the original github post this code is based from.

A "Comments" option/button is above the send button for every request.
But still, we can't add a comment in the request body, maybe in future, they'll provide this feature.

I checked with GitHub where Postman has their feature requests and bugs tracked, Link here:
Feature request: Raw body editor JSON comment #3358
https://github.com/postmanlabs/postman-app-support/issues/3358
You can go and add comments there so that this feature would be considered for their next release. Also, I found out that you can copy and paste <!-- comment--> to make a comment.

It has been done by Script
https://community.postman.com/t/request-body-should-be-able-to-be-commented/8288
Pre-request Script create an object, convert it to a string, then expose it
object = {
// product: "{{displayName}}",
price : "15.5"
}
pm.environment.set("object", JSON.stringify(object));
Request Body called the variable object
{{object}}

In Postman v9.13.0 you can do so using block comments

Not the actual question's answer, but this addresses the highly upvoted comment below the question:
I just want to disable some code not want to add comments or descriptions..how can I do that? – Mahender Reddy Yasa
Ignoring the comment validation and sending request is now working for me in latest postman 7.7.3 64 bit version of windows.

Related

How to add a variable from Json extractor into an array in JMeter?

I'm new here and also a beginner on JMeter and maybe this was already answered in an old post that I didn't find, sorry if this is the case.
I had this Post request I need to send with all these IDs that vary according to the account
Post Request
In order to get all of the IDs, I used the JSon extractor to put then into a variable
JSon extractor, then I got all the FieldIDs that I need.
ID extracted
But now how can I add this variable inside the request? I tried something like {"ids":"${fieldId}","includeBoundary":true} but it didn't work. How can I use this?
Please see: HTTP Request parameter dialog example
If you need to extract the whole response, save it into a JMeter Variable and send it back to another endpoint - the easiest way is using Boundary Extractor providing empty left and right boundaries
If you need more complex transformations - take a look at JSR223 Test Elements and Groovy language
I solved my problem in a so easy way(damn it)!!!!
On the Json extractor I just marked the option "Computer concatenation var (suffix_ALL)" then on the debbuger I got all IDs I needed in only one line and finally on my request I just add on the body data the line {"ids": [${fieldId_ALL}],"includeBoundary":true} and bingo it worked like a charm!!!!

JMETER: Need to send all entries in a CSV file to HTTP request body in 'one' request

I'm trying to solve a test data issue in Jmeter. Can anyone of you have a look at below problem statement and advise here please ?
Requirement: Need to send all entries in a CSV file to HTTP request body in 'one' request to the end point.
Example CSV File:
"adsfas123wsf00000wqefqwe52145t10000",
"fdfrgvergq120947r0000dwsfqwaef237sadf",
"wfrqwef7865034r78tkahsefjh6985r7asfdaf",
"qefqwe52145t10000adsfas123wsf00000w",
"wsfqwaef237sadffdfrgvergq120947r0000d"
HTTP Request Body:
["${data}"}]
When the data is substituted, I should be able to get below output.
[
"adsfas123wsf00000wqefqwe52145t10000",
"fdfrgvergq120947r0000dwsfqwaef237sadf",
"wfrqwef7865034r78tkahsefjh6985r7asfdaf",
"qefqwe52145t10000adsfas123wsf00000w",
"wsfqwaef237sadffdfrgvergq120947r0000d"
]
Problem Statement: When I use CSV data set config. file, I'm unable to concatenate all entries into one single request body. My understanding is, CSV data set config. the file is not the right option here.
Did some search in StackOverflow and followed a method to achieve above using JSR223 PreProcessor' and the link is, How to send multiple json body using jmeter?.
Followed the above link and tried added below custom code provided.
def builder = new StringBuilder()
new File('/path/to/plans.csv').readLines().each { line ->
builder.append(new File(line).text).append(System.getProperty('line.separator'))
}
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', builder.toString(), '')
sampler.setPostBodyRaw(true)
Upon running, I get below error message,
Caused by: java.io.FileNotFoundException,
"adsfas123wsf00000wqefqwe52145t10000",
"fdfrgvergq120947r0000dwsfqwaef237sadf",
"wfrqwef7865034r78tkahsefjh6985r7asfdaf",
"qefqwe52145t10000adsfas123wsf00000w",
"wsfqwaef237sadffdfrgvergq120947r0000d" (The filename, directory name, or volume label syntax is incorrect)
If the file is not found, then how come the entries are read and displayed in the log viewer?
Also, how do I link the output of custom code to the request body? Or is it taken care of by the custom code itself?
You have an error in your code, change this line:
builder.append(new File(line).text).append(System.getProperty('line.separator'))
to this one:
builder.append(line).append(System.getProperty('line.separator'))
If you want to send the full contents of the file you don't even need to go for scripting, you can use __FileToString() function right in the "Body data" tab of the HTTP Request sampler:
${__FileToString(/path/to/plans.csv,,)}
And last but not the least if you need to generate JSON from the plain text it might be a better idea to go for JsonBuilder class, see Apache Groovy - Why and How You Should Use It and Apache Groovy - Parsing and producing JSON
Two steps:
Add a User Parameter Pre-processor before the HTTP request:
Name: DATA
User_1: ${__FileToString(/path/to/plans.csv,,)}
Add the following to request body:
${DATA}

reCaptcha invalid json response

Using the recaptcha javascript client ( http://www.google.com/recaptcha/api.js?onload=vcRecaptchaApiLoaded&render=explicit ) the automatic request (GET https://www.google.com/recaptcha/api2/userverify?k=XXXXXXXXX) after you select the correct images returns an invalid json which afterwards is sent to back to google and their json validation fails. This worked as expected for months now. Not anymore :(
Server side library used reCaptcha PHP (1.1)
Response
)]}'
["uvresp","03AHJ_Vuup5SJJ583dSIfezFl80dp2AlJ_rZpz3vqGWlOTmbjZqH8izwjruJASNhQI0tOOnmj2Pzg14xMw7dryeqVfTGhx6dg_x2i0PRA1ZeDyrBNn8DX-w5S262Zb3_ZWKj5JDBiqPVnXtNLGbyBxjd97VHanspJWU_-qKWLSWVKxLK6n3lm9Biw33oUCEiGA39GNa09Z6TSAEtnolQCf_LPPRWKoE_e50f2s5ZpUVG5GNVdX7qGBRwphTgcUhwOjA8uYTzmA9co3Jwk2KR5UQ0zzVRJzRZZTBuK9km3PE1WV05ACAwrJi29niDpVaRmpooAnIkHNgGyGBu7u3W7gU6YAHtwya8PYhdF__G_MMG8XpVFDTBa196hKD6hxw-E2PsxmoIQJrU1K89mmzNIh-xLNQ7KJvrBMzVf8A5FHyUQgL5UNDWVwSkWCdC_3swxBzi7R3p8VIrUtkIqJFA_GSAxy0cBRJ8J55Pfs5rzhfR8j-x1hGCzi_6vJrbrwfNesoLEB7GWJtElcljhBYvcDNzU_B_VJ7Sck-6i1Nd0qdmtSiCRZYNyaZ8uGLoDdNgCY-0Oi4802AlI26H7TjGBcKnr4gmaHXTNRf1W7x_3FV05DxVsTqeAlo8zGqmiVqcgmX64BbLK4fD9Xoait1_Lp5vK26fCaOQmGKF7CJaYPuxnX-zXgSkfZDCG6rs6xv1CfZQnIKD0W3Yz522VD4YdNfATb3FywhFWbZuxoBIt6vslZDlPXh2MYOkAmYfIPIo8WoWazMoLI_8iNBZPiMlRL0PS5aQiLSrvbf-sknMHhfM2MJYsfrQjC52aDRaHYdcZbY6Wxlhw0tQEknX8B47_DAQzCKkpoFsecO1eMHuInIykZ1l7TOdZMytI-NzGg21KeKAE8dK6ZWee0UEqDJvCkj5aH5TQcBA--ygbOS186bAptUP5n6WvORx1Nb2ZU_AF9fB23PJWH1xvB4gZoNDvhLmdpkE1Po9Lyim1P61E2rrgYjWgPRwT4jUo",1,120]
Any ideas?
Thanks
I think it's a duplicate of https://stackoverflow.com/a/36862268/2140017
And here is my answer from that link:
Actually the value returned is not valid json but well parsed by the
Google's API.
Is it a protection ? I don't know, but if you look at the javascript,
you can find that:
var jm=function(a,b,c,d,e,g,h,l,r){this.xl=a;this.$c=c||"GET";this.Ka=d;this.Gg=e||null;this.Td=m(h)?h:1;this.ye=0;this.xh=this.Nh=!1;this.uh=b;this.Mh=g;this.md=l||"";this.Zb=!!r;this.Wf=null};f=jm.prototype;f.getUrl=function(){return this.xl};f.ug=function(){return this.$c};f.Ca=function(){return this.Ka};f.fi=function(){return this.Zb};f.bi=function(){return this.md};var nm=function(){G.call(this);this.nj=new hm(0,mm,1,10,5E3);H(this,this.nj);this.ad=0};x(nm,G);var mm=new Nh;nm.prototype.send=function(a){return new Lc(function(b,c){var d=String(this.ad++);this.nj.send(d,a.Uf.toString(),a.ug(),a.Ca(),mm,void 0,u(function(a,d){var h=d.target;if(Xk(h)){var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;b(new l(h))}else c(new om(a))},this,a))},this)};var om=function(a){y.call(this);this.request=a};x(om,y);
especially take a look at:
var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;`
The parser explicitly checks that the value begins by )]} and strips
it.
I suggest you to just apply the same substring on the "json" string

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.

JMeter not attaching contents of binary file to POST data in HTTP Request

I'm attempting to simulate a login call with JMeter 2.11 to a service that uses a binary format. I've created an Http Request with the appropriate settings, except for the body data. I need to POST raw binary data.
According to the docs here, I should be able to set the file path for exactly one file, with no parameter name, and no other content in the Body Data, and have it place the data in the request body.
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 after version 2.2, and also for PUT requests after version 2.3.
However, when I run the test, the POST Data is empty.
I have tried the extra set of plugins for JMeter as well, but alas, I'm stuck. The loaded file has 145 bytes of data, and the request shows that the content-length is 0. What am I missing?
The Http Request
The result
Update 1
To clarify, I am NOT attempting to send a file, I'm attempting to send a binary encoded message as raw POST data.
Switch back to Parameters tab not Post body.
See:
http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request
Yoy could try recoring to see how the resuest look like.
This is my solution,maybe not best, but it works fine:
1st step :
You should write your binary data to a file (assume it's name is
FILENAME);
2nd step :
For your http request sampler,Yout should put ${FILENAME} under file
path in the "Send Files with the request" section (while leaving its
paramter name empty and specifying an encoding (for binary, it is
application/binary)).
Hope it helps.
Refer to this article

Resources