Reputation: 819
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
Reputation: 1
How to use a path parameter in Rest Assured:
eg.
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
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
Reputation: 819
Instead of
.pathParam("pageNo", "1")
Changed to
.queryParam("pageNo", "1")
This worked.
Upvotes: 5