I am trying to generate a URI for fetching delta records from ServiceNow API. While executing my program, I create a filter and concatenate the same with the original uri and by using get method of RestAssured, I extract the results. Although the above steps are working for full extract but somehow when I try to generate a URI with filter conditions, I am getting an illegal character error.
I have written the following function, for getting the data from API:-
public static void getURIIncrementalExtract(String tblName, String params) {
RestAssured.baseURI = null;
String params = ""; //For stackoverflow
String displayValueParam = "sysparm_display_value=true&";
String dateParams = "";
dateParams = "sysparm_query=col_updated_on>=2017-09-30"; //+ fromDate
String uri = "https://[servicenowAPIadd].com/api/now/table/" + tblName + "?" + displayValueParam + params + dateParams;
System.out.println(uri); //URI generated is working correctly in postman.
RestAssured.baseURI = uri;
}
//The uri generated by above function //https://[servicenowAPIadd].com/api/now/table/[DBtablename]?sysparm_display_value=true&sysparm_query=col_updated_on>=2017-09-30
public static Response getResponseByPath() {
Response response = null;
try {
response = RestAssured.given()
.when()
.auth()
.basic(username, password)
.get(RestAssured.baseURI);
} catch (Exception e) {
e.printStackTrace();
log.error("Exception in getResponseByPath:-" + e.toString());
}
return response;
}
In the main method, I call the getURIIncrementalExtract followed by getResponseByPath.
I am getting an illegal syntax exception whenever I try to add the sysparm_query filters. If I remove the filter i.e. "sysparm_query=col_updated_on>=2017-09-30", it works fine.
I am expecting to generate and use the URI for filtered data as well. I think the way I am generating the URI can be wrong. Can someone share a right approach please. Please let me know if further information is required.