srikanthsrigir…

Unable to Create Package using RESTS APIs

0 votes
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

0 votes
Hey Srikanth, If you take a look at the documentation page you linked, if you are just doing a package creation without document binaries, you don't need the "multi-part form" configuration of the payload. You should just need to send along the JSON string through the "writer". Hope this helps.

- Michael

Director, Partner and Developer Technologies, OneSpan

Facebook - Twitter - LinkedIn


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off