Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

"Invalid number of path parameters. Expected 0, was 3" error while passing the url parameters in rest api (rest-assured)

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.

Upvotes: 7

Views: 20159

Answers (3)

Mehraj Hossain
Mehraj Hossain

Reputation: 1

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

Upvotes: 0

Stevo
Stevo

Reputation: 141

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

Upvotes: 4

Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

Instead of

.pathParam("pageNo", "1")

Changed to

.queryParam("pageNo", "1")

This worked.

Upvotes: 5

Related Questions