Rest assured getting null point when Response data value is inserted in Post Request

Viewed 17

I am using GET API to list the available slots and storing the first available slot ID and passing it to the POST API as query param in.I am using get and past in different class file. when i try to execute i am getting NULL in the POST API

I am getting null pointer exception in the below post when passing the ID value from Search Class

public class Search {

    @Step("user perform a GET search")
    public void SearchCurrentDay() {
        String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("base.api.url");
        response = SerenityRest.given().contentType("application/json")
                .header("Content-Type", "application/json")
                .when().queryParam("type", 2)
                .queryParam("date_req", today.toString())
                .get(BASEURI + basePath);
        System.out.println("Search json response:::==>" + response.prettyPrint());
        id = response.jsonPath().getString("id[0]");
        
    }
}

public class BookAppointment extends Search {

    @Step("user perform a POST request to book request Today")
    public void BookingCurrentDay(){
        String BASEURI = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("store.api.url");
        logger.info("~~~~~ id_from_get~~~~ :: {}", id);
        response = SerenityRest.given().contentType("application/json")
                .header("Content-Type", "application/json")
                .when()
                .queryParam("bookingid", id)
                .queryParam("fname","test")
                .queryParam("lname", "lname")
                .queryParam("dob", "1985-11-11")
                .post(BASEURI +basePath);
        System.out.println("jsonResponse:::" + response.prettyPrint());

    }
}
0 Answers
Related