0

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": {...}
        }
SFa
  • 3
  • 2
  • What is the full error message? – Code-Apprentice Oct 22 '21 at 16:44
  • I am assuming it is something with the special chars in the key name. The underscore or the colon that is making Java choke. Sucks you have to move from Python to a crap language like Java. ;) – james-see Oct 22 '21 at 16:44
  • The strangest thing as far as the error message goes is that when I try to catch the exception and log the full error, I haven't been getting it. I'll take a look as far as how special characters go and double check to make sure I'm catching the exception properly. – SFa Oct 22 '21 at 16:51
  • 1
    If your Java code crashes, we need to see the Java code, not some Python you try to rewrite. The actual JSON input may be helpful, too. See [mcve]. – Robert Oct 22 '21 at 16:59

0 Answers0