I'm adapting some Python code that gets JSON submission data from a third party API and performs some operations on it. In the python, it filters by two fields in the JSON, created_at and status. I'm able to filter by status in java, but whenever I even try to add created_at to the filter, I get a NullPointerException. For reference, the python I'm adapting is above and my code is below. Updated to include the full function that's failing and
order_data = requests.get(form_url, headers=thirdparty_header,
params={'filter': json.dumps({'created_at:gt': look_back, 'status': 'ACTIVE'}), 'limit': '1000'})
orders = order_data.json()['content']
private JSONObject getFormData() {
URL url = null;
JSONObject json = new JSONObject();
json.put("created_at:gt", yesterday);//formatted yyyy-mm-dd 00:00:00
json.put("status", "ACTIVE");
String params = "?filter=" + json;
url = new URL("https://thirdparty.com/submissions" + params.toString());
HttpURLConnection c;
c = (HttpURLConnection) url.openConnection();
c.setRequestProperty("APIKEY", apikey);
c.setRequestMethod("GET");
c.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
System.out.println(line + "\n");
}
JSONObject obj = new JSONObject(sb.toString());
br.close();
return obj;
}
Json requested:
"responseCode": 200,
"message": "success",
"content": [
{
"id": "5555555555555",
"form_id": "44444444444",
"ip": "0.0.0.0",
"created_at": "2021-10-19 12:56:05",
"status": "ACTIVE",
"new": "1",
"flag": "0",
"notes": "",
"updated_at": null,
"answers": {...}
}