Unable to Create Package using RESTS APIs
Sunday, November 6, 2016 at 08:41pm
Hi Haris,
I am trying to create new package and then updload the document at a later point after creating package. 
Basically i want to it separate the steps. (create packages , upload document(s) to the created package).
I have picked up the package input payload from http://docs.e-signlive.com/mc/content/c_esignlive_integrator_s_guide/rest_api/packages.htm
Can you please look at below code and let me know what is missing in below code. Thanks in Advance.
	    public static void createPackage() throws MalformedURLException, IOException {
		private static final String requestURL = "https://sandbox.esignlive.com/api";
		private static final String apiKey = "";
		private static final String charset = "UTF-8";
		private static final String CRLF = "\r\n"; // Line separator used in multipart/form-data.
   
        HttpsURLConnection connection = null;
        URL url = new URL(requestURL + "/packages/");
        connection = (HttpsURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        
        //connection.setRequestProperty("Content-Type","multipart/form-data; boundary=" +boundary);
        connection.setRequestProperty("Content-Type","application/json");
        connection.setRequestProperty("Authorization", "Basic " + apiKey);
        connection.setRequestProperty("Accept", "application/json");
		
		// JSON copied from http://docs.e-signlive.com/mc/content/c_esignlive_integrator_s_guide/rest_api/packages.htm
        String JSONPackage = "{\"name\": \"My Document\",\"type\":\"PACKAGE\",\"language\":\"en\",\"emailMessage\":\"[email protected]\",\"description\":\"New Package\",\"autoComplete\":true}";
        OutputStream output = connection.getOutputStream();
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);        
        
        writer.append("--" + boundary).append(CRLF);
        writer.append(CRLF).flush();
        
        // add json payload
        writer.append("--" + boundary).append(CRLF);
        writer.append("Content-Disposition: form-data; name=\"payload\"").append(CRLF);
        writer.append("Content-Type: application/json; charset=" +
                      charset).append(CRLF);
        writer.append(CRLF).append(JSONPackage).append(CRLF).flush();
        // End of multipart/form-data.
        writer.append("--" + boundary + "--").append(CRLF).flush();
        //get and write out response code
        int responseCode = ((HttpURLConnection)connection).getResponseCode();
        System.out.println(responseCode);
        
		}
Thanks
Srikanth.
 
      
                                    
Reply to: Unable to Create Package using RESTS APIs
Tuesday, November 8, 2016 at 07:42am