public JSONArray getItems(int page, int itemsPerPage, String type, boolean showDeleted)
      throws CloudApiException {
    HttpGet request = null;
    try {
      // Sanitize the parameters
      if (page < 1) {
        page = 1;
      }
      if (itemsPerPage < 1) {
        itemsPerPage = 1;
      }

      // Prepare the list of parameters.
      List<NameValuePair> nvps = new ArrayList<NameValuePair>();
      nvps.add(new BasicNameValuePair("page", "" + page));
      nvps.add(new BasicNameValuePair("per_page", "" + itemsPerPage));
      if (type != null) {
        nvps.add(new BasicNameValuePair("type", type));
      }
      nvps.add(new BasicNameValuePair("deleted", (showDeleted) ? "true" : "false"));

      // Prepare the URI (the host and querystring.)
      URI uri = URIUtils.createURI(serviceUrl.getScheme(),
          serviceUrl.getHost(), serviceUrl.getPort(), "/items",
          URLEncodedUtils.format(nvps, "UTF-8"), null);

      // Prepare the request.
      request = new HttpGet(uri);
      request.addHeader("Accept", "application/json");

      // Perform the request.
      HttpResponse response = client.execute(request);
      response.addHeader("Accept", "application/json");
      int status = response.getStatusLine().getStatusCode();
      String body = EntityUtils.toString(response.getEntity(), "UTF-8");

      // We always need 200 for items retrieval.
      if (status == 200) {
        return new JSONArray(body);
      }

      // Anything else is a failure.
      throw new CloudApiException(status, body, null);

    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Error when trying to retrieve the items.", e);
      throw new CloudApiException(500, e.getMessage(), e);
    } catch (JSONException e) {
      LOGGER.log(Level.WARNING, "Error when trying to parse the response as JSON.", e);
      throw new CloudApiException(500, e.getMessage(), e);
    } catch (URISyntaxException e) {
      LOGGER.log(Level.WARNING, "Error when trying to retrieve the items.", e);
      throw new CloudApiException(500, e.getMessage(), e);
    } finally {
      if (request != null) {
        request.abort();
      }
    }
  }