… // Example list of Ric to delete ArrayList ricToDelete = new ArrayList(); ricToDelete.add("AAPL.O"); ricToDelete.add("IBM.N"); ricToDelete.add("FCHA.MI"); ArrayList instrumentListItemKeys = new ArrayList(); // Obtain the list of InstrumentListItemKey from the list of Ric instrumentListItemKeys = dss2.getInstrumentListItemKeys_AllInstruments(myListId2, ricToDelete); promptEnterKey(); //* Delete the list of InstrumentsListItemKey from the list id if(instrumentListItemKeys!=null && instrumentListItemKeys.size()>0) { dss2.deleteInstrumentsFromList(myListId2,instrumentListItemKeys); } public ArrayList getInstrumentListItemKeys_AllInstruments(String listID, ArrayList ricToDelete) { ArrayList instrumentListItemKeys=new ArrayList(); try { String urlGet = urlHost + "/Extractions/InstrumentLists('" + listID + "')/ThomsonReuters.Dss.Api.Extractions.InstrumentListGetAllInstruments"; HttpGet request = new HttpGet(urlGet); request.addHeader("Authorization", "Token "+sessionToken); HttpResponse response = httpclient.execute(request); System.out.println("Get all instruments. HTTP status: " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } System.out.println("JSON results received:\n"+result); JSONObject jsonGetResponse = new JSONObject(result.toString()); String userDetail = jsonGetResponse.get("value").toString(); System.out.println("All Instruments: " +userDetail); JSONArray valueJArray = jsonGetResponse.getJSONArray("value"); for (int j = 0; j < ricToDelete.size(); j++) { for (int i = 0; i < valueJArray.length(); i++){ if( valueJArray.getJSONObject(i).getString("IdentifierType").equalsIgnoreCase("Ric") && valueJArray.getJSONObject(i).getString("Identifier").equals(ricToDelete.get(j)) ) { instrumentListItemKeys.add(valueJArray.getJSONObject(i).getString("InstrumentListItemKey")); System.out.println("\nFind Ric "+ricToDelete.get(j)+" . InstrumenListItemKeys: "+valueJArray.getJSONObject(i).getString("InstrumentListItemKey")); break; } } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instrumentListItemKeys; } public void deleteInstrumentsFromList(String listId, ArrayList instrumentListItemKeys) { try { HttpPost httppost = new HttpPost(urlHost + "/Extractions/InstrumentLists('"+listId+"')/ThomsonReuters.Dss.Api.Extractions.InstrumentListDeleteItemsById"); httppost.addHeader("content-type", "application/json;odata.metadata=minimal"); httppost.addHeader("Authorization", "Token " + sessionToken); //String instrumentKey = "VjF8MHgwNzQ4ZWUxYWY3YjZmNzRhfDU"; JSONArray jsArray = new JSONArray(); for (int j = 0; j < instrumentListItemKeys.size(); j++) { jsArray.put(instrumentListItemKeys.get(j)); } JSONOrderedObject instListJSONObject = new JSONOrderedObject() .put("InstrumentListItemKeys", jsArray); System.out.println("Instrument addition JSON request content:\n"+ instListJSONObject.toString()); StringEntity requestBody = new StringEntity(instListJSONObject.toString()); httppost.setEntity(requestBody); ResponseHandler responseHandler = new BasicResponseHandler(); HttpResponse response2 = httpclient.execute(httppost); for (int j = 0; j < instrumentListItemKeys.size(); j++) { System.out.println("Deleting InstrumentListItemKey: "+ instrumentListItemKeys.get(j)); } System.out.println("HTTP status: " + response2.getStatusLine().getStatusCode()); // It will receive response code 204 with no content if (response2.getStatusLine().getStatusCode() == 204){ System.out.println("Delete InstrumentListItemKey completed."); } else if (response2.getStatusLine().getStatusCode() == 404){ System.out.println("InstrumentListItemKey not found."); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }