Here's my Java code for creating the JSON (I'm generating random values for the line items)...
JSONObject bulkItems = new JSONObject(); JSONArray ja = new JSONArray(); JSONObject jo; for (int i = 0; i < 3; i++) { jo = new JSONObject(); jo.put("name", IdUtils.getRandomString(6)); jo.put("price", (long) random.nextInt(2000)); jo.put("quantitySold", df.format(random.nextDouble() * 10)); jo.put("unitName", "ea"); ja.put(jo); } bulkItems.put("items", ja);When I convert bulkItems to a JSON string, it looks exactly like the sample string in the REST api_docs.
{ "items": [{ "name": "WTGDC9", "price": 1725, "quantitySold": "2.44", "unitName": "ea" }, { "name": "0JPYJS", "price": 663, "quantitySold": "6.07", "unitName": "ea" }, { "name": "TP7QP9", "price": 1211, "quantitySold": "1.53", "unitName": "ea" }] }When I send this to the bulk_line_items endpoint, I get the error message:
org.json.JSONException: Value [{"id":"Y8ESY2SP7MZ9G","name":"WTGDC9","price":1725,"unitName":"ea","printed":false,"createdTime":1522909087000,"orderClientCreatedTime":1522909087000,"exchanged":false,"refunded":false,"isRevenue":true},{"id":"Q7TVNDJ48WJA2","name":"0JPYJS","price":663,"unitName":"ea","printed":false,"createdTime":1522909087000,"orderClientCreatedTime":1522909087000,"exchanged":false,"refunded":false,"isRevenue":true},{"id":"YZ0QXRAAP0F44","name":"TP7QP9","price":1211,"unitName":"ea","printed":false,"createdTime":1522909087000,"orderClientCreatedTime":1522909087000,"exchanged":false,"refunded":false,"isRevenue":true}] of type org.json.JSONArray cannot be converted to JSONObject
Any help on what I'm doing wrong?