code: public static String urlEncode(String str) throws UnsupportedEncodingException {
      // Preserve original behavior that passing null for an object id will lead
      // to us actually making a request to /v1/foo/null
      if (str == null) {
        return null;
      } else {
        // Don't use strict form encoding by changing the square bracket control
        // characters back to their literals. This is fine by the server, and
        // makes these parameter strings easier to read.
        return URLEncoder.encode(str, CHARSET)
          .replaceAll("%5B", "[")
          .replaceAll("%5D", "]");
      }
    }
docs: URL-encodes a string.