C# : How to post more than PDF file to eSignLive (new interface)
Monday, August 22, 2016 at 05:35pmHi eSignLive Team,
I am working on an integration between eSign Live and Ebix Inc. Life eApp and in this integration we require to perform in person signature ceremony , and I created a console application in .Net C# and having an issue (Bad Request 400 and Can not deserialize instance of java.util.ArrayList ) while sending multiple PDFs to eSignLive and didn't get the package Id however it worked fine for a single PDF file.
Here is the require details which you need to troubleshot this issue:
1. URL : "https://sandbox.esignlive.com/api" where I am posting request for package creation.
2. Already setup an account at eSign Live new interface and using api key while making a request.
3. .Net console application code.
string url = "https://sandbox.esignlive.com/api";
string jsonFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", "RNAJson.txt"); /* Load json string from a file.*/
string jsonString = File.ReadAllText(jsonFilePath);
string jsontoken = "";
string jsonpackageId = "";
StringContent jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
string pdfFilename1 = "1964-Application.pdf";
string pdfFilepath1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", pdfFilename1);
string pdfFilename2 = "1964-Application-RNAC-AR.pdf";
string pdfFilepath2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", pdfFilename2);
MultipartFormDataContent form = new MultipartFormDataContent();
/*Add first PDF file in Data content*/
byte[] fileByteArray1 = File.ReadAllBytes(pdfFilepath1);
ByteArrayContent content1 = new ByteArrayContent(fileByteArray1);
content1.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
content1.Headers.ContentDisposition.Name = "\"file\"";
content1.Headers.ContentDisposition.FileName = "\"" + pdfFilename1 + "\"";
content1.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
form.Add(content1);
/*Add second PDF file in Data content*/
byte[] fileByteArray2 = File.ReadAllBytes(pdfFilepath2);
ByteArrayContent content2 = new ByteArrayContent(fileByteArray2);
content2.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
content2.Headers.ContentDisposition.Name = "\"file\"";
content2.Headers.ContentDisposition.FileName = "\"" + pdfFilename2 + "\"";
content2.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
form.Add(content2);
form.Add(jsonContent, "\"payload\"");
var boundaryValue = form.Headers.ContentType.Parameters.FirstOrDefault(p => p.Name == "boundary");
boundaryValue.Value = boundaryValue.Value.Replace("\"", String.Empty);
try
{
HttpClient myClient = new HttpClient();
myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", apiKey);
myClient.DefaultRequestHeaders.Add("Accept", "application/json");
var response = myClient.PostAsync(new Uri(url) + "/packages/", form).Result;
jsonpackageId = response.Content.ReadAsStringAsync().Result;
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
eSignPackageID PackageID = jsSerializer.Deserialize(jsonpackageId);
using (var client = new WebClient())
{
byte[] res =
client.UploadValues("https://sandbox.esignlive.com/api/authenticationTokens", new NameValueCollection()
{
{ "Content-Type", "application/json" },
{ "Accept", "application/json" },
{ "Authorization", "Basic " + apiKey}
});
jsontoken = System.Text.Encoding.UTF8.GetString(res);
jsSerializer = new JavaScriptSerializer();
eSignTokenID TokenID = jsSerializer.Deserialize(jsontoken);
Console.WriteLine("https://sandbox.esignlive.com" + "/auth?authenticationToken=" + TokenID.value + "&target=https://sandbox.esignlive.com/a/transaction/" + PackageID.id + "/sign");
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Error : {0}", ex.Message);
}
4. Error message
{"messageKey":"error.validation.invalidJson","technical":"Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: {\r\n \"roles\": [\r\n {\r\n \"id\": \"PRIMARY_AGENT\",\r\n \"index\": \"1\",\r\n \"name\": \"PRIMARY_AGENT\",\r\n \"signers\": [\r\n {\r\n \"delivery\": {\r\n \"email\": \"false\"\r\n },\r\n \"firstName\": \"Melody\",\r\n \"lastName\": \"Sievert\",\r\n \"email\": \"[email protected]\",\r\n \"id\": \"PRIMARY_AGENT\"\r\n }\r\n ]\r\n },\r\n {\r\n \"id\": \"PRIMARY_INSURED\",\r\n \"index\": \"2\",\r\n \"name\": \"PRIMARY_INSURED\",\r\n \"signers\": [\r\n {\r\n \"delivery\": {\r\n \"email\": \"false\"\r\n },\r\n \"firstName\": \"Lonnie\",\r\n \"lastName\": \"Adams\",\r\n \"email\": \"[email protected]\",\r\n \"id\": \"PRIMARY_INSURED\"\r\n }\r\n ]\r\n },\r\n {\r\n \"id\": \"OWNER\",\r\n \"index\": \"3\",\r\n \"name\": \"OWNER\",\r\n \"signers\": [\r\n {\r\n \"delivery\": {\r\n \"email\": \"false\"\r\n },\r\n \"firstName\": \"Lonnie\",\r\n \"lastName\": \"Adams\",\r\n \"email\": \"[email protected]\",\r\n \"id\": \"OWNER\"\r\n }\r\n ]\r\n }\r\n ],\r\n \"documents\": [\r\n {\r\n \"approvals\": [\r\n {\r\n \"fields\": [\r\n {\r\n \"binding\": \"{approval.signed}\",\r\n \"extract\": \"true\",\r\n \"name\": \"Insured_Signature\",\r\n \"subtype\": \"CAPTURE\",\r\n \"type\": \"SIGNATURE\"\r\n }\r\n ],\r\n \"name\": \"documentInsured_Signature\",\r\n \"role\": \"PRIMARY_INSURED\"\r\n },\r\n {\r\n \"fields\": [{\r\n \"binding\": \"{approval.signed}\",\r\n \"extract\": \"true\",\r\n \"name\": \"Owner_Signature\",\r\n \"subtype\": \"CAPTURE\",\r\n \"type\": \"SIGNATURE\"\r\n }],\r\n \"name\": \"documentOwner_Signature\",\r\n \"role\": \"PRIMARY_AGENT\"\r\n }\r\n ],\r\n \"extract\": \"true\",\r\n \"id\": \"document1\",\r\n \"index\": \"1\",\r\n \"name\": \"1964-Application.pdf\"\r\n },\r\n {\r\n \"approvals\": {\r\n \"fields\": [\r\n {\r\n \"binding\": \"{approval.signed}\",\r\n \"extract\": \"true\",\r\n \"name\": \"Writing_Agent_Signature\",\r\n \"subtype\": \"CAPTURE\",\r\n \"type\": \"SIGNATURE\"\r\n }\r\n ],\r\n \"name\": \"documentWriting_Agent_Signature\",\r\n \"role\": \"PRIMARY_AGENT\"\r\n },\r\n \"extract\": \"true\",\r\n \"id\": \"document2\",\r\n \"index\": \"2\",\r\n \"name\": \"1964-Application-RNAC-AR.pdf\"\r\n }\r\n ],\r\n \"settings\": {\r\n \"ceremony\": {\r\n \"events\": {\r\n \"complete\": {\r\n \"dialog\": \"true\",\r\n \"redirect\": \"\"\r\n }\r\n },\r\n \"inPerson\": \"true\",\r\n \"declineButton\": \"true\",\r\n \"hideOwnerInPersonDropdown\": \"true\",\r\n \"disableFirstInPersonAffidavit\": \"true\",\r\n \"disableInPersonAffidavit\": \"true\",\r\n \"disableOptOutOther\": \"false\",\r\n \"disableSecondInPersonAffidavit\": \"true\",\r\n \"documentToolbarOptions\": {\r\n \"downloadButton\": \"true\"\r\n },\r\n \"handOver\": {\r\n \"title\": \"You will be redirected to Google homepage\",\r\n \"href\": \"http://www.google.com\",\r\n \"text\": \"Exit to site\"\r\n },\r\n \"hideCaptureText\": \"true\",\r\n \"hideLanguageDropdown\": \"true\",\r\n \"hidePackageOwnerInPerson\": \"true\",\r\n \"hideWatermark\": \"true\",\r\n \"maxAuthFailsAllowed\": \"3\",\r\n \"optOutButton\": \"true\",\r\n \"optOutReasons\": [\r\n \"Decline terms.\"\r\n ],\r\n \"style\": null,\r\n \"layout\": {\r\n \"footer\": {},\r\n \"iframe\": \"true\",\r\n \"navigator\": \"true\",\r\n \"brandingBar\": {\r\n \"logo\": {\r\n \"src\": \"http://www.logo-maker.net/images/common/company-logo8.gif\",\r\n \"link\": \"\"\r\n }\r\n },\r\n \"header\": {\r\n \"feedback\": \"true\",\r\n \"globalActions\": {\r\n \"confirm\": \"true\",\r\n \"download\": \"false\",\r\n \"hideEvidenceSummary\": \"false\",\r\n \"saveAsLayout\": \"false\"\r\n },\r\n \"titleBar\": {\r\n \"title\": \"true\",\r\n \"progressBar\": \"true\"\r\n },\r\n \"breadcrumbs\": \"false\",\r\n \"globalNavigation\": \"false\",\r\n \"sessionBar\": \"true\"\r\n }\r\n }\r\n }\r\n },\r\n \"name\": \"RNAC-1964\",\r\n \"type\": \"PACKAGE\",\r\n \"language\": \"en\",\r\n \"emailMessage\": \"\",\r\n \"description\": \"RNA e-signature package\",\r\n \"autoComplete\": \"true\",\r\n \"status\": \"SENT\"\r\n}; line: 86, column: 20] (through reference chain: com.silanis.esl.api.model.Package[\"documents\"]->java.util.ArrayList[1]->com.silanis.esl.api.model.Document[\"approvals\"])","code":400,"message":"Invalid JSON.","name":"Validation Error"}
5. JSON request.
{
"roles": [
{
"id": "PRIMARY_AGENT",
"index": "1",
"name": "PRIMARY_AGENT",
"signers": [
{
"delivery": {
"email": "false"
},
"firstName": "Melody",
"lastName": "Sievert",
"email": "[email protected]",
"id": "PRIMARY_AGENT"
}
]
},
{
"id": "PRIMARY_INSURED",
"index": "2",
"name": "PRIMARY_INSURED",
"signers": [
{
"delivery": {
"email": "false"
},
"firstName": "Lonnie",
"lastName": "Adams",
"email": "[email protected]",
"id": "PRIMARY_INSURED"
}
]
},
{
"id": "OWNER",
"index": "3",
"name": "OWNER",
"signers": [
{
"delivery": {
"email": "false"
},
"firstName": "Lonnie",
"lastName": "Adams",
"email": "[email protected]",
"id": "OWNER"
}
]
}
],
"documents": [
{
"approvals": [
{
"fields": [
{
"binding": "{approval.signed}",
"extract": "true",
"name": "Insured_Signature",
"subtype": "CAPTURE",
"type": "SIGNATURE"
}
],
"name": "documentInsured_Signature",
"role": "PRIMARY_INSURED"
},
{
"fields": [{
"binding": "{approval.signed}",
"extract": "true",
"name": "Owner_Signature",
"subtype": "CAPTURE",
"type": "SIGNATURE"
}],
"name": "documentOwner_Signature",
"role": "PRIMARY_AGENT"
}
],
"extract": "true",
"id": "document1",
"index": "1",
"name": "1964-Application.pdf"
},
{
"approvals": {
"fields": [
{
"binding": "{approval.signed}",
"extract": "true",
"name": "Writing_Agent_Signature",
"subtype": "CAPTURE",
"type": "SIGNATURE"
}
],
"name": "documentWriting_Agent_Signature",
"role": "PRIMARY_AGENT"
},
"extract": "true",
"id": "document2",
"index": "2",
"name": "1964-Application-RNAC-AR.pdf"
}
],
"settings": {
"ceremony": {
"events": {
"complete": {
"dialog": "true",
"redirect": ""
}
},
"inPerson": "true",
"declineButton": "true",
"hideOwnerInPersonDropdown": "true",
"disableFirstInPersonAffidavit": "true",
"disableInPersonAffidavit": "true",
"disableOptOutOther": "false",
"disableSecondInPersonAffidavit": "true",
"documentToolbarOptions": {
"downloadButton": "true"
},
"handOver": {
"title": "You will be redirected to Google homepage",
"href": "http://www.google.com",
"text": "Exit to site"
},
"hideCaptureText": "true",
"hideLanguageDropdown": "true",
"hidePackageOwnerInPerson": "true",
"hideWatermark": "true",
"maxAuthFailsAllowed": "3",
"optOutButton": "true",
"optOutReasons": [
"Decline terms."
],
"style": null,
"layout": {
"footer": {},
"iframe": "true",
"navigator": "true",
"brandingBar": {
"logo": {
"src": "http://www.logo-maker.net/images/common/company-logo8.gif",
"link": ""
}
},
"header": {
"feedback": "true",
"globalActions": {
"confirm": "true",
"download": "false",
"hideEvidenceSummary": "false",
"saveAsLayout": "false"
},
"titleBar": {
"title": "true",
"progressBar": "true"
},
"breadcrumbs": "false",
"globalNavigation": "false",
"sessionBar": "true"
}
}
}
},
"name": "RNAC-1964",
"type": "PACKAGE",
"language": "en",
"emailMessage": "",
"description": "RNA e-signature package",
"autoComplete": "true",
"status": "SENT"
}
6. HTTP post logs.
POST https://sandbox.esignlive.com/api/packages/ HTTP/1.1
Authorization: Basicapikey
Accept: application/json
Content-Type: multipart/form-data; boundary=d5950353-ad45-4c43-a2a5-b3dd6c304129
Host: sandbox.esignlive.com
Content-Length: 376873
Expect: 100-continue
Connection: Keep-Alive
--d5950353-ad45-4c43-a2a5-b3dd6c304129
Content-Disposition: form-data; name="file"; filename="1964-Application.pdf"
Content-Type: application/pdf
--d5950353-ad45-4c43-a2a5-b3dd6c304129
Content-Disposition: form-data; name="file"; filename="1964-Application-RNAC-AR.pdf"
Content-Type: application/pdf
Please help me to resolve this issue.
Thanks,
Deep
Reply to: C# : How to post more than PDF file to eSignLive (new interface)
Tuesday, August 23, 2016 at 08:13am