var ApplicationCode = request.data["ApplicationCode"];
var Version=request.data["version"];
var ReferenceId=request.data["referenceId"];
var ProductCode=request.data["productCode"];
var Quantity=request.data["quantity"];
var SecretKey="e56067172e61";
var hashText = ApplicationCode+ProductCode+Quantity+ReferenceId+Version+SecretKey;
var encryption = CryptoJS.MD5(hashText).toString();
postman.setEnvironmentVariable("Signature", encryption);
Hi @kizildagcenk, you’re using the correct method to set the variable in the pre-request script.
One thing I’d like to point out on the last line is that you can use pm.environment.set("Signature", encryption);
This is the new API and I recommend using it.
Also, in the raw body, you’ve to surround the Signature variable with quotes.
So your raw body actually becomes the following:
{
"referenceId": "022078925508",
"productCode": "001002461285",
"quantity": "1",
"version": "V1",
"signature": "{{Signature}}", // notice the quotes here around the variable
"applicationCode": "52e7cf966b724749a7c4efadc3727ed7"
}
Now run your script and it should work as expected.
Thank you for your reply @singhsivcan, I m getting error from the service. I think they want content-type = application/x-www-form-urlencoded. Is there a way to convert this to application/x-www-form-urlencoded?
I know this is an older post/has been closed for a while. But is there a limit to the variable size? I am trying to get a description from a JIRA issue and use it as a variable to create another one.
The syntax you mention, “{{Variable}}”, works for me in Body Raw JSON when using variables such as Date or Title from the JIRA issue, but when using the description I am getting the following error:
{
“errorMessages”: [
“Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@7fc7314c; line: 13, column: 39]”
]
}
I am able to get the request to work when I copy in the description value into the JSON Body (even its entire length )
Any suggestions?
Edit:
So I was able to answer my own question.
Using stringify() to set my variable seems to fix my problem:
Since this question is still pulling a lot of views we’ve created a collection that shows how to achieve that in the Postman Answers public workspace:
Hi! I am in a similar situation, but this didn’t completely work for me. I have my request in a folder that contains a pre-request script to calculate an HMAC over the request’s body.
What seems to happen is that the pre-request script of the request is run after the pre-request of the folder, so I tried moving the
What I want to achieve is to generate the items array elements, because I have to send 10.000 items in one POST request.
How can I replace the array’s items?
It will be slightly different if you’re pulling that data from a variable but be you’re need to ensure that it’s in the correct format of it wouldn’t resolve the data correctly.