6

Trying to test the rest api with rest-assured. Getting the error

Invalid number of path parameters. Expected 0, was 3.

public class GetSociailDetails {

    @Test
    public void generateToken() {

        Map<String,String> userDetails = new HashMap<>();

        userDetails.put("msISDN", "1217071016");
        userDetails.put("messageSource", "TWITTER");
        userDetails.put("socialId", "168988132");

        given()
        .contentType("application/json")

        .pathParam("access_token", "LLRPqxvU1uoT8YSl8")

        .pathParam("pageNo", "1")

        .pathParam("order", "desc")

        .body(userDetails)

        .post("http://name.com/rest/crm/getdetails")

        .then()

        .statusCode(200);

    }

}

Is there a different way to pass the url params in the rest api which is of POST method.

Nagarjuna Reddy
  • 759
  • 9
  • 19
  • 39

3 Answers3

4

Instead of

.pathParam("pageNo", "1")

Changed to

.queryParam("pageNo", "1")

This worked.

Nagarjuna Reddy
  • 759
  • 9
  • 19
  • 39
4

When using path params you need to add in the 'mapping' to the URL where you expect your param to appear. e.g in your example, if you changed your post request to the following it will work:

.post("http://name.com/rest/crm/getdetails/{access_token}/{pageNo}/{order}")

This will result in the following URL based on your example:

http://name.com/rest/crm/getdetails/LLRPqxvU1uoT8YSl8/1/desc
Stevo
  • 141
  • 5
0

How to use a path parameter in Rest Assured:

  1. Use pathParam method to add the path parameter to the end of the base URI

eg.

  1. Base URI:https://www.example.com/
  2. Path Param: resource/{resourceID}

Full Code:

RestAssured.given().baseUri("https://www.example.com/").pathParam("resourceID","Resource123").get(/resource/{resourceID});

Full URI: https://www.example.com/resource/Resource123