Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 03:13am
0
votes
Hi,
Can you provide a sample JSON request Body to Create Package with Document Content as a PDF Byte Stream.
Thanks
October 19Created
January 21Last Updated
7 years agoLast Reply
11Replies
214Views
3Users
0Likes
0Links
harishaidary | Posts: 1812
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 03:39am
0
votes
Have a look at our Create and Send a Package Quick Start guide: https://developer.esignlive.com/guides/quick-start/creating-and-sending-a-package-rest/
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 04:00am
0
votes
And see in the example there is code to create the transaction. I am trying to test in POSTMAN, so just need a sample of the body to send. I am using the create package from the quikstart as my starting point, just not clear on how to include PDF byte stream in the body.
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, October 25, 2016 at 12:27pm
0
votes
Guys,
Did you get any solution to this problem, I am facing same issue.
getting webpage code returned , not JSON is using this REST with JAVA "https://developer.esignlive.com/guides/quick-start/creating-and-sending-a-package-rest/"
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 26, 2016 at 05:50am
0
votes
There was an issue with the JSON payload in the quick start guide. The "lastName" field was missing for the signer. I will go ahead and update the quick start guide. Here's the working code (updated to handle errors):
package example.codes;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import javax.net.ssl.HttpsURLConnection;
public class CreateAndSendPackageRest {
public static void main(String[] args) throws MalformedURLException, IOException {
HttpsURLConnection connection = null;
String requestURL = "https://sandbox.esignlive.com/api/packages";
String apiKey = "api_key";
String charset = "UTF-8";
File uploadFile1 = new File("C:/Users/hhaidary/Desktop/PDFs/doc1.pdf");
String boundary = Long.toHexString(System.currentTimeMillis());
String CRLF = "\r\n"; // Line separator used in multipart/form-data.
String jsonContent = "{\"roles\":[{\"locked\":false,\"emailMessage\":{\"content\":\"\"},\"attachmentRequirements\":[],\"reassign\":false,\"specialTypes\":[],\"id\":\"Sender\",\"data\":null,\"type\":\"SIGNER\",\"index\":0,\"signers\":[{\"auth\":{\"challenges\":[],\"scheme\":\"NONE\"},\"company\":\"Silanis\",\"firstName\":\"yourFirst\",\"lastName\":\"yourLast\",\"phone\":\"\",\"email\":\"[email protected]\",\"knowledgeBasedAuthentication\":null,\"language\":\"en\",\"title\":\"Silanis\",\"external\":null,\"professionalIdentityFields\":[],\"userCustomFields\":[],\"delivery\":{\"email\":true,\"provider\":false,\"download\":true},\"group\":null,\"signature\":null,\"address\":null,\"data\":null,\"name\":\"\",\"specialTypes\":[]}],\"name\":\"Sender\"},{\"locked\":false,\"emailMessage\":{\"content\":\"\"},\"attachmentRequirements\":[],\"reassign\":false,\"specialTypes\":[],\"id\":\"Signer\",\"data\":null,\"type\":\"SIGNER\",\"index\":0,\"signers\":[{\"auth\":{\"challenges\":[],\"scheme\":\"NONE\"},\"company\":\"\",\"firstName\":\"signerFirst\",\"lastName\":\"signerLast\",\"phone\":\"\",\"email\":\"[email protected]\",\"knowledgeBasedAuthentication\":null,\"language\":\"en\",\"title\":\"\",\"external\":null,\"professionalIdentityFields\":[],\"userCustomFields\":[],\"delivery\":{\"email\":false,\"provider\":false,\"download\":false},\"group\":null,\"id\":\"Signer\",\"signature\":null,\"address\":null,\"data\":null,\"name\":\"\",\"specialTypes\":[]}],\"name\":\"Signer\"}],\"documents\": [{\"approvals\":[{\"role\":\"Signer\",\"signed\":null,\"accepted\":null,\"data\":null,\"fields\":[{\"page\":0,\"subtype\":\"FULLNAME\",\"width\":200,\"binding\":null,\"extract\":false,\"extractAnchor\":null,\"left\":175,\"top\":165,\"validation\":null,\"height\":50,\"data\":null,\"type\":\"SIGNATURE\",\"value\":\"\"}],\"name\":\"\"},{\"role\":\"Sender\",\"signed\":null,\"accepted\":null,\"data\":null,\"fields\":[{\"page\":0,\"subtype\":\"FULLNAME\",\"width\":200,\"binding\":null,\"extract\":false,\"extractAnchor\":null,\"left\":550,\"top\":165,\"validation\":null,\"height\":50,\"data\":null,\"type\":\"SIGNATURE\",\"value\":\"\"}],\"name\":\"\"}],\"name\": \"sampleAgreement\"}],\"name\": \"Test Package REST\", \"type\":\"PACKAGE\", \"language\":\"en\", \"emailMessage\":\"\", \"description\":\"New Package\",\"autoComplete\":true,\"status\":\"SENT\"}";
URL url = new URL(requestURL);
connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
connection.setRequestProperty("Authorization", "Basic " + apiKey);
connection.setRequestProperty("Accept", "application/json; esl-api-version=11.0");
OutputStream output = connection.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
try {
// Add pdf file.
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + uploadFile1.getName() + "\"")
.append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(uploadFile1.getName()))
.append(CRLF);
writer.append("Content-Transfer-Encoding: application/pdf").append(CRLF);
writer.append(CRLF).flush();
Files.copy(uploadFile1.toPath(), output);
output.flush();
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(jsonContent).append(CRLF).flush();
// End of multipart/form-data.
writer.append("--" + boundary + "--").append(CRLF).flush();
} catch (IOException ex) {
System.err.println(ex);
}
// get and write out response code
int responseCode = ((HttpURLConnection) connection).getResponseCode();
System.out.println(responseCode);
if (responseCode == 200) {
// get and write out response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
} else {
// get and write out response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
}
}
}
Don't forget to replace the api_key placeholder with your own value.
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 26, 2016 at 09:39am
0
votes
Thanks Haris,
I got it worked by changing way to make connection, however, after getting packageId, roleId, I am getting signingUrl properly... . but it gives this error when tried to open (both from postman URL and through REST using Java code)
ESR.min.js?_=1469563549483:3 Uncaught Error: Could not find a valid role
at f._role_ (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:12281)
at f (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:2703)
at Array.forEach (native)
at f.c [as set] (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:2945)
at f.init (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:11646)
at new f (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:2:31020)
at b (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:290)
at https://sandbox.esignlive.com/javascript/vendor/augment/lib/augment.js:447:23
at Array.map (native)
at f.add (https://sandbox.esignlive.com/javascript/lib/ESL/ESR.min.js?_=1469563549483:3:1516)
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:29am
0
votes
Make sure that you have indeed added a signer to your package and that this signer has at least one signature on a document. Both of these are required when retrieving the signing url. Also, the package status has to be in SENT status. The error message that you are getting means that you are retrieving a signing url for a signer that isn't present in your package.
http://docs.esignlive.com/content/c_integrator_s_guide/rest_api/signing_url.htm
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:49am
0
votes
Thanks Harish,
That worked for me when i sent an unlocked pdf and it opened appropriately, however it gives issue for some other unlocked pdfs/ or i upload directly from inputstream (rather then form any C drive or so).
Trying to figure out the root cause.
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:59am
0
votes
Yes, in order to upload a document to esignlive, there shouldn't be any restrictions on it. If you open your document with Adobe Reader for example and go to the document properties, the security section should look like the following:
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, November 1, 2016 at 06:16am
0
votes
Haris,
When I am trying JSON with PDF having signatures for document-extraction, it fails with an issue, not sure what is cause (NOTE: we have only 1 pdf with multiple pages).
NOTE: Same JSON when tried with similar One document - multiple pages (WITHOUT SIGNATURES TAGS IN pdf)... wokred well and gave URL for signing
JSON:
{"roles":[{"locked":false,"emailMessage":{"content":""},"attachmentRequirements":[],"reassign":false,"specialTypes":[],"id":"Signer","data":null,"type":"SIGNER","index":0,"signers":[{"auth":{"challenges":[],"scheme":"NONE"},"company":"Assurant","firstName":"Pammy","lastName":"Singh","phone":"","email":"[email protected]","knowledgeBasedAuthentication":null,"language":"en","title":"Assurant","external":null,"professionalIdentityFields":[],"userCustomFields":[],"delivery":{"email":true,"provider":false,"download":true},"group":null,"signature":null,"address":null,"data":null,"name":"","specialTypes":[]}],"name":"Signer"},{"locked":false,"emailMessage":{"content":""},"attachmentRequirements":[],"reassign":false,"specialTypes":[],"id":"Sender","data":null,"type":"SENDER","index":0,"signers":[{"auth":{"challenges":[],"scheme":"NONE"},"company":"Assurant","firstName":"Permender","lastName":"Matharu","phone":"","email":"[email protected]","knowledgeBasedAuthentication":null,"language":"en","title":"","external":null,"professionalIdentityFields":[],"userCustomFields":[],"delivery":{"email":false,"provider":false,"download":false},"group":null,"id":"Sender","signature":null,"address":null,"data":null,"name":"","specialTypes":[]}],"name":"Sender"}],"documents": [{"approvals":[{"role":"Signer","signed":null,"accepted":null,"data":null,"fields":[{"page":0,"subtype":"FULLNAME","width":0,"binding":null,"extract":true,"extractAnchor":null,"left":0,"top":0,"validation":null,"height":0,"data":null,"type":"SIGNATURE","value":""}],"name":""}],"name": "signTags"}],"name": "Test Package REST", "type":"PACKAGE", "language":"en", "emailMessage":"", "description":"New Package","autoComplete":true,"status":"SENT"}
PDF:
- its Unlocked
- it has tags as [Signer.SomeName]
Error:
{
"messageKey": "error.validation.package.wrongNumberOfFiles",
"technical": "Number of uploaded files does not match number of documents specified in package.",
"message": "Number of uploaded files does not match number of documents specified in package.",
"code": 400,
"name": "Validation Error"
}
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, November 1, 2016 at 07:48am
0
votes
Hi,
There are a couple of mistakes I should point out. First, if you're looking to use document extraction, you don't need to declare any approvals. You only to set extract to true. Here's what you json payload should be:
Next, [Signer.SomeName] is not a valid form field name. They should be something like [Signer.Capture1] where Capture1 is the signature style (this can't be some random name). More information about document extraction is available here: http://docs.esignlive.com/content/c_integrator_s_guide/sdk/c_managing_documents/extraction.htm
Make those changes and let me know if it works for you.
Reply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 03:39amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 03:57amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 19, 2016 at 04:00amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, October 25, 2016 at 12:27pmReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 26, 2016 at 05:50amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Wednesday, October 26, 2016 at 09:39amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:29amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:49amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Thursday, October 27, 2016 at 04:59amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, November 1, 2016 at 06:16amReply to: Sample JSON request Body to Create Package with Document Content as Byte Stream
Tuesday, November 1, 2016 at 07:48am