0
votes

There is a JAVA REST API (Put request) that I want to hit with values from a CSV file.

The CSV file is:

enter image description here

The JMETER CSV configuration is:

enter image description here

This is how I have set up the JMETER Configuration to hit the API:

enter image description here

The deserialisation on the Java side is not happening correctly. From POSTMAN, the following works:

{
  "productId": "ABC",
  "score": 4.42489
}

Why is the Jmeter POST configuration not working correctly?

Error: Received Unknown exception com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of double from String value '$score': not a valid Double value

Update: On doing this in Jmeter configuration:

{
    "productId" : "${product}",
    "score": "${score}"
}

I got the following error:

Received Unknown exception com.fasterxml.jackson.core.JsonParseException: Unexpected character ('T' (code 84)): was expecting comma to separate OBJECT entries at [Source: java.io.PushbackInputStream@4063ce7d; line: 2, column: 18] Similarly for M, M and R. So 4 errors in total.

Update 2:[Solved]The following CSV Data Set Configuration worked without any change in the actual CSV file!!

enter image description here

A Big Thank you to @user7294900 for the help!!

3
Shouldn't you use delimiter as , instead of /n as your CSV file shows that data is comma separated?Amol Chavan

3 Answers

1
votes

i do wonder if you might also have a problem with product_id being the parameter name versus productID that works directly in postman.

1
votes

You forgot curly braces (this is not velocity/postman)

You need to send HTTP Request Body Data:

{
    "productId": "${product}",
    "score": "${score}"
}

Check the maunual for more details:

Variables are referenced as follows:

${VARIABLE}

Also your quotes in CSV file is redundant, either change Allow quoted data to true or better yet remove all quotes " from CSV file.

0
votes

You don't need quotation marks around "${product}" and ${score} as:

  1. Your CSV file already has quotations around ProductId I don't think you need duplicate ones
  2. Your application expects a Double and you are basically sending a String

So change your payload to look like:

{
    "productId" : ${product},
    "score": ${score}
}

More information: