Search code examples
javaapiseleniumrest-assuredrest-assured-jsonpath

How to pass parameter in request body of restassured api in JAVA?


In below example, if i run this it is taking z as string, not as parameter, 

String z=   "1234";
        System.out.println("converted"+z);
        try {
            RestAssured.baseURI = "http://192.189.11.51:05/oceans/fssdata/";
            String requestBody ="{\"CompanyID\":z"
                    + ""
                    + ""
                    + "}";`

How to pass parameter Z in company ID, right now it is taking company id as z, I want it should take the value of z.


Solution

  • You need to be careful with escaping the quotation marks when using strings directly. You can try using the code below.

    String z = "\"1234\"";
    
    String requestBody: "{\"name\":"+z+"}";