arun_thipparthi

API request into equivalent SDK code

0 votes
HI All, Can you help me to convert the below API request into equivalent SDK code to create the package(with one document file as attachment to sign off): { "name": "packagename", "status": "SENT", "roles": [ { "id": "signer1", "index": "1", "type": "SIGNER", "signers": [ { "email": "[email protected]", "firstName": "TestUser1", "lastName": "TestUser1", "delivery": { "email": false, "provider": false, "download": false } } ] }, { "id": "signer2", "index": "1", "type": "SIGNER", "signers": [ { "email": "[email protected]", "firstName": "TestUser2", "lastName": " TestUser2", "delivery": { "email": false, "provider": false, "download": false } } ] }, { "id": "employee", "index": "0", "type": "SIGNER", "signers": [ { "email": "[email protected]", "firstName": "Employee1", "lastName": " Employee1", "delivery": { "email": false, "provider": false, "download": false } } ] } ], "documents": [ { "extract": true, "name": "SaskatchewanLoanProtectionPlan", "index": 0, "fields": [ { "FieldName": "CUSTNUM", "FieldValue": "2321495" }, { "FieldName": "CUSTBR", "FieldValue": "2546" }, { "FieldName": "CUSTSURNAME", "FieldValue": "Houlihan" } ] } ] } Thanks in advance.

Reply to: API request into equivalent SDK code

0 votes
Hi arun,
public void createPackage2() {
		// Build the DocumentPackage object
		DocumentPackage documentPackage = newPackageNamed("packagename")
				.withSigner(newSignerWithEmail("[email protected]")
						.withCustomId("signer1")
						.withFirstName("TestUser1").withLastName("TestUser1")
						.signingOrder(1)
						)
				.withSigner(newSignerWithEmail("[email protected]")
						.withCustomId("signer2")
						.withFirstName("TestUser2").withLastName("TestUser2")
						.signingOrder(1)
						)
				.withSigner(newSignerWithEmail("[email protected]")
						.withCustomId("employee")
						.withFirstName("Employee1").withLastName("Employee1")
						.signingOrder(0)
						)
				.withDocument(newDocumentWithName("SaskatchewanLoanProtectionPlan")
						.fromFile(URL_PATH)
						.enableExtraction()
						.atIndex(0)
						.withInjectedField(FieldBuilder.textField()
								.withName("CUSTNUM")
								.withValue("2321495"))
						.withInjectedField(FieldBuilder.textField()
								.withName("CUSTBR")
								.withValue("2546"))
						.withInjectedField(FieldBuilder.textField()
								.withName("CUSTSURNAME")
								.withValue("Houlihan"))
						)
				.build();

		// Issue the request to the e-SignLive server to create the DocumentPackage
		PackageId packageId = eslClient.createAndSendPackage(documentPackage);
	}
This is the sample code created for you. And “delivery”: {“email”: false,“provider”: false,“download”: false}this part is set to false by default I think. If you are using Text Injection, please make sure the pdf form property name is in consistent with your field name. And if you are applying Document Extraction, .enableExtraction() function is enough to tell OneSpan Sign the info of your approvals and fields. But if you are using other kinds of extraction, please do the corresponding changes in the code. Hope this could help you! Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: API request into equivalent SDK code

0 votes
Hi Duo Ling, Thanks for the code, I am able to create the package with the above code you shared. One more followup question, In the current code we have directly provided document path .withDocument(newDocumentWithName("SaskatchewanLoanProtectionPlan") .fromFile(URL_PATH) Instead of file path I have base64 encoded PDF content how can I set the string content as document? When I tried with below changes I am getting exception: InputStream is = new ByteArrayInputStream(org.apache.commons.codec.binary.Base64.encodeBase64(docAsBytes)); DocumentBuilder db= newDocumentWithName(name) .fromStream(is, DocumentType.PDF) Exception I received is : Exception in thread "main" com.silanis.esl.sdk.internal.EslServerException: Could not upload document to package. Exception: HTTP POST on URI https://sandbox.esignlive.com/api/packages/ZAZbFqmJ6f-6NUwVg5Qm4jisEjU=/documents resulted in response with status code: [500, Internal Server Error]. Optional details: {"technical":"error.eslx.inputValidation.documentPreverifyError [#32865abc-534f-4e09-9e71-e554114782df]","messageKey":"error.internal.default","message":"Unexpected error. We apologize for any inconvenience this may have caused you, please try again. If the problem persists, please contact our support team.","code":500,"name":"Unhandled Server Error"} at com.silanis.esl.sdk.service.PackageService.uploadApiDocument(PackageService.java:264) at com.silanis.esl.sdk.service.PackageService.uploadDocument(PackageService.java:249) at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:598) at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:610) at com.silanis.esl.sdk.EslClient.createPackage(EslClient.java:265) at com.silanis.esl.sdk.EslClient.createAndSendPackage(EslClient.java:452) at com.goeasy.esb.mule.components.esign.ESignLivePackage.processPackage(ESignLivePackage.java:75) at com.goeasy.esb.mule.components.esign.ESignLivePackage.main(ESignLivePackage.java:36) Caused by: com.silanis.esl.sdk.internal.RequestException: HTTP POST on URI https://sandbox.esignlive.com/api/packages/ZAZbFqmJ6f-6NUwVg5Qm4jisEjU=/documents resulted in response with status code: [500, Internal Server Error]. Optional details: {"technical":"error.eslx.inputValidation.documentPreverifyError [#32865abc-534f-4e09-9e71-e554114782df]","messageKey":"error.internal.default","message":"Unexpected error. We apologize for any inconvenience this may have caused you, please try again. If the problem persists, please contact our support team.","code":500,"name":"Unhandled Server Error"} at com.silanis.esl.sdk.internal.RestClient.execute(RestClient.java:192) at com.silanis.esl.sdk.internal.RestClient.postMultipartFile(RestClient.java:132) at com.silanis.esl.sdk.service.PackageService.uploadApiDocument(PackageService.java:260) Note: In both the cases I used the same PDF. which is working when I provide the path, but failing when I provide the stream. Kindly guide me. Thanks in advance

Reply to: API request into equivalent SDK code

0 votes
Hi Arun, I believe OneSpan Sign can't receive base64 encoding string. Can you decode it before converting into the InputStream? Or you just skip this step?
InputStream is = new ByteArrayInputStream(byteArray);
DocumentBuilder db= newDocumentWithName(name)
                      .fromStream(is, DocumentType.PDF);
This two lines work well from my testing. Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: API request into equivalent SDK code

0 votes
Hi Arun, And here's a snippet which works fine to convert PDF into byte[]:
	File file = new File(sourcePath);
        int size = (int) file.length();
        if (size > Integer.MAX_VALUE) {
            System.out.println("File is to larger");
        }
        byte[] bytes = new byte[size];
        DataInputStream dis = new DataInputStream(new FileInputStream(file));
        int read = 0;
        int numRead = 0;
        while (read = 0) {
            read = read + numRead;
        }
        dis.close();
        InputStream testStream3 = new ByteArrayInputStream(bytes);
I don't know whether it makes sense to you as in the code, the FileInputStream is actually used to generate the byte[] and then you'd use byte[] to generate an InputStream. And since I don't know what kind of data you are handling. Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


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