Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SIGNNOW_API_HOST=https://api.signnow.com
SIGNNOW_API_BASIC_TOKEN=c2lnbk5vdyBBUEkgc2FtcGxlIEFwcCB2MS4wCg==
SIGNNOW_API_USERNAME=user@signnow.com
SIGNNOW_API_PASSWORD=coolest_pazzw0rd
SIGNNOW_API_TIMEOUT=30

# Absolute or relative (starts with .) path to the directory
# where the downloaded files will be stored (make sure you have write permissions to this directory)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
.env.backup
.env.production
.env.development
examples/signnow-example.properties
examples/files/bulk_real.csv
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: mock-up mock-stop mock-restart test tests
.PHONY: mock-up mock-stop mock-restart test tests example examples

.SILENT: ; # no need for @
.ONESHELL: ; # recipes execute in same shell
Expand Down Expand Up @@ -34,3 +34,15 @@ test:
# Run all the tests
tests:
mvn test

# Run an example from examples/ directory
# Examples:
# make example E=DocumentGetExample
# make examples
example:
@if [ -z "$(E)" ]; then echo "Usage: make example E=ExampleClassName"; exit 1; fi
./examples/bin/run $(E)

# Run all examples
examples:
./examples/bin/run all
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# signNow API Java SDK
## v3.5.1
## v3.5.2

[![Java Version](https://img.shields.io/badge/codebase-java--11-yellowgreen)](https://www.java.com/)

Expand Down
11 changes: 4 additions & 7 deletions examples/AuthCheckExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

public class AuthCheckExample {
public static void main(String[] args) {

// Set your actual input data here
// Note: following values are dummy, just for example
//----------------------------------------------------
// if it is empty or null, a new Bearer token will be created automatically
String bearerToken = "";

// Fill in your actual data in examples/signnow-example.properties before running
//---------------------------------------------------
SignNowExampleData data = new SignNowExampleData();
String bearerToken = data.getBearerToken();
try {
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);
TokenGetResponse response = (TokenGetResponse) client.send(new TokenGetRequest()).getResponse();
Expand Down
14 changes: 7 additions & 7 deletions examples/BulkInviteExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

public class BulkInviteExample {
public static void main(String[] args) {
// Fill in your actual data in examples/signnow-example.properties before running

// Set your actual input data here
// Note: following values are dummy, just for example
// Details: https://docs.signnow.com/docs/signnow/template/operations/create-a-template-bulkinvite
//----------------------------------------------------
// if it is empty or null, a new Bearer token will be created automatically
String bearerToken = "";
SignNowExampleData data = new SignNowExampleData();
String bearerToken = data.getBearerToken();
// CSV file containing information for each invite in the bulk
// Example: Signer 1|user@signnow.com,Contract_0_Jack
// "Signer 1" - signing role, must present in the template
// "user@signnow.com" - signer email related for the signing role
// "Contract_0_Jack" - contains 3 parts: "Contract" - document name, 0 - line/invite number,
// "Jack" - signer name
String csvFilePath = "/your/path/to/data.csv";
String csvFilePath = data.getBulkInviteCsvFilePath();
// The template from which a new document will be cloned for each invite in the bulk.
// The template must have at least one field assigned the same signing role that exists in your csv file
// (i.e. "Signer 1")
// Look at TemplateExample.java to find out how to create a template.
// Look at FieldInviteExample.java to find out how to add a field to document or template.
String templateId = "e2e913db4ba9815a31c8a28a196b7df96fe1cc46";
String templateId = data.getBulkInviteTemplateId();
// The folder to store documents cloned from the template.
String folderId = "3073f8da73b9a5328f95ccc55a912e3f46da2d94";
String folderId = data.getBulkInviteFolderId();
String documentNameClonedFromTemplate = "test_bulk_invite";
// Set your actual input data here, or use these as examples
String bulkInviteSubject = "email subject for all signers from CSV";
String bulkInviteMessage = "email message for all signers from CSV";

Expand Down
23 changes: 17 additions & 6 deletions examples/DocumentGetExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

public class DocumentGetExample {
public static void main(String[] args) {

// Set your actual input data here
// Note: following values are dummy, just for example
// Fill in your actual data in examples/signnow-example.properties before running
//----------------------------------------------------
// if it is not specified here, a new Bearer token will be created automatically
String bearerToken = "";
String documentId = "05fbed799231d85cf3471121ecd6a4221f9c5610";
SignNowExampleData data = new SignNowExampleData();
String bearerToken = data.getBearerToken();
String documentId = data.getDocumentId();

try {
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);
Expand All @@ -22,6 +20,19 @@ public static void main(String[] args) {
System.out.println("Document ID: " + response.getId());
System.out.println("Document Name: " + response.getDocumentName());
System.out.println("Document Owner: " + response.getUserId());

// These fields are available when using ?include=field_invites query parameter
if (response.getGeneralExpirationDays() != null) {
System.out.println("General Expiration Days: " + response.getGeneralExpirationDays());
}
if (response.getGeneralReminder() != null) {
System.out.println("General Reminder - After: " + response.getGeneralReminder().getRemindAfter()
+ ", Before: " + response.getGeneralReminder().getRemindBefore()
+ ", Repeat: " + response.getGeneralReminder().getRemindRepeat());
}
if (response.getOrderType() != null) {
System.out.println("Order Type: " + response.getOrderType());
}
} catch (SignNowApiException e) {
System.out.println("ERROR: " + e.getMessage());
}
Expand Down
27 changes: 19 additions & 8 deletions examples/DocumentGroupInviteExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@

public class DocumentGroupInviteExample {
public static void main(String[] args) {

// Set your actual input data here
// Note: following values are dummy, just for example
// Fill in your actual data in examples/signnow-example.properties before running
//----------------------------------------------------
// if it is not specified here, a new Bearer token will be created automatically
String bearerToken = "";
SignNowExampleData data = new SignNowExampleData();
String bearerToken = data.getBearerToken();
String pathToDocument = data.getPathToDocument();
String signerRole = data.getDocumentGroupInviteSignerRole();
String signerEmail = data.getDocumentGroupInviteSignerEmail();
// Set your actual input data here, or use these as examples
String groupName = "Test Document Group";
String signerRole = "Signer";
String signerEmail = "signer@signnow.com";
String subject = "Please sign these documents";
String message = "Hello, please sign these documents";
String pathToDocument = "/your/path/to/document.pdf";

try {
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);
Expand Down Expand Up @@ -103,6 +102,18 @@ public static void main(String[] args) {
GroupInvitePostResponse inviteResponse = (GroupInvitePostResponse) client.send(inviteRequest).getResponse();

System.out.println("Document Group: " + docGroupResponse.getId());
// These fields are available when using ?include=reminder query parameter
if (docGroupResponse.getGeneralExpirationDays() != null) {
System.out.println("General Expiration Days: " + docGroupResponse.getGeneralExpirationDays());
}
if (docGroupResponse.getGeneralReminder() != null) {
System.out.println("General Reminder - After: " + docGroupResponse.getGeneralReminder().getRemindAfter()
+ ", Before: " + docGroupResponse.getGeneralReminder().getRemindBefore()
+ ", Repeat: " + docGroupResponse.getGeneralReminder().getRemindRepeat());
}
if (docGroupResponse.getOrderType() != null) {
System.out.println("Order Type: " + docGroupResponse.getOrderType());
}
System.out.println("Document Group invite: " + inviteResponse.getId());
} catch (SignNowApiException e) {
System.out.println("ERROR: " + e.getMessage());
Expand Down
183 changes: 122 additions & 61 deletions examples/DocumentGroupRecipientsExample.java
Original file line number Diff line number Diff line change
@@ -1,91 +1,152 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.signnow.api.document.request.DocumentPostRequest;
import com.signnow.api.document.request.DocumentPutRequest;
import com.signnow.api.document.request.data.Field;
import com.signnow.api.document.request.data.FieldCollection;
import com.signnow.api.document.response.DocumentPostResponse;
import com.signnow.api.documentgroup.request.DocumentGroupGetRequest;
import com.signnow.api.documentgroup.request.DocumentGroupPostRequest;
import com.signnow.api.documentgroup.request.data.DocumentIdCollection;
import com.signnow.api.documentgroup.response.DocumentGroupGetResponse;
import com.signnow.api.documentgroup.response.DocumentGroupPostResponse;
import com.signnow.api.documentgroup.request.DocumentGroupRecipientsGetRequest;
import com.signnow.api.documentgroup.request.DocumentGroupRecipientsPutRequest;
import com.signnow.api.documentgroup.request.data.CcCollection;
import com.signnow.api.documentgroup.request.data.GeneralReminder;
import com.signnow.api.documentgroup.request.data.recipient.Attribute;
import com.signnow.api.documentgroup.request.data.recipient.Document;
import com.signnow.api.documentgroup.request.data.recipient.DocumentCollection;
import com.signnow.api.documentgroup.request.data.recipient.Recipient;
import com.signnow.api.documentgroup.request.data.recipient.RecipientCollection;
import com.signnow.api.documentgroup.response.DocumentGroupRecipientsGetResponse;
import com.signnow.api.documentgroup.response.DocumentGroupRecipientsPutResponse;
import com.signnow.core.ApiClient;
import com.signnow.core.exception.SignNowApiException;
import com.signnow.core.factory.SdkFactory;
import java.io.File;

public class DocumentGroupRecipientsExample {
public static void main(String[] args) {
// Set your actual input data here
// Note: following values are dummy, just for example
// ----------------------------------------------------
// if it is not specified here, a new Bearer token will be created automatically
String bearerToken = "";
String documentGroupId = "5d66ca4accdd4ab28f8b2c71001093b5cb3bcb8a";
// Fill in your actual data in examples/signnow-example.properties before running
SignNowExampleData data = new SignNowExampleData();
String bearerToken = data.getBearerToken();
String pathToDocument = data.getPathToDocument();
String firstRecipientRole = data.getFirstRecipientRole();
String secondRecipientRole = data.getSecondRecipientRole();
String signAction = data.getSignAction();
String viewAction = data.getViewAction();
// Set your actual input data here, or use these as examples
String groupName = "Test Document Group Recipients Example";
String recipientOrder = "recipient_order"; // at_the_same_time, recipient_order, advanced_order
int expirationDays = 31;

try {
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);

// Get recipient
DocumentGroupRecipientsGetRequest request = new DocumentGroupRecipientsGetRequest()
.withDocumentGroupId(documentGroupId);
DocumentGroupRecipientsGetResponse response = (DocumentGroupRecipientsGetResponse) client.send(request)
.getResponse();
// Precondition:
// the document group contains 2 documents both with a field assigned a signer role
//----------------------------------------------------
// Step 1: Upload two documents to become a document group
DocumentPostRequest request = new DocumentPostRequest(new File(pathToDocument));
DocumentPostResponse response = (DocumentPostResponse) client.send(request).getResponse();
String documentId1 = response.getId();
// Step 2: Add fields with roles to the 1st document
FieldCollection fields = new FieldCollection();
fields.add(
new Field(205, 18, 122, 12, "text", 0, true, firstRecipientRole, "text_field1", "Reason to sign"));
DocumentPutRequest putRequest1 = new DocumentPutRequest(fields);
putRequest1.withDocumentId(documentId1);
client.send(putRequest1);
// Step 3: Upload 2nd document
DocumentPostRequest request2 = new DocumentPostRequest(new File(pathToDocument));
DocumentPostResponse response2 = (DocumentPostResponse) client.send(request2).getResponse();
String documentId2 = response2.getId();
// Step 4: Add fields and roles to the 2nd document
FieldCollection fields2 = new FieldCollection();
fields2.add(
new Field(220, 24, 142, 14, "text", 0, true, secondRecipientRole, "text_field2", "My reason"));
DocumentPutRequest putRequest2 = new DocumentPutRequest(fields2);
putRequest2.withDocumentId(documentId2);
client.send(putRequest2);
// Step 5: Create document group
DocumentIdCollection documentIds = new DocumentIdCollection();
documentIds.add(documentId1);
documentIds.add(documentId2);
DocumentGroupPostRequest groupRequest = new DocumentGroupPostRequest(documentIds, groupName);
DocumentGroupPostResponse groupResponse =
(DocumentGroupPostResponse) client.send(groupRequest).getResponse();
String documentGroupId = groupResponse.getId();

// Convert to request model and replace email
RecipientCollection recipientCollection = new RecipientCollection();
for (com.signnow.api.documentgroup.response.data.data.Recipient responseRecipient : response.getData()
.getRecipients()) {
Recipient reqRecipient = convertRecipient(responseRecipient);
if (reqRecipient == null) continue;

System.out.println("Original name: " + responseRecipient.getName());
System.out.println("Original email: " + responseRecipient.getEmail());
// PUT /v2/document-groups/{document_group_id}/recipients
DocumentCollection docs1 = new DocumentCollection();
// Signer recipient: should review and sign the document
docs1.add(new Document(documentId1, firstRecipientRole, signAction));
Attribute signerAttribute = Attribute.signer(false, true, false, "Please sign", "Signing request", null, null, null);
Recipient recipient1 = new Recipient("John Doe", "john.doe@example.com", 1, docs1, null, signerAttribute);

if (reqRecipient.getName().equals("Recipient 1")) {
// Replace email
Recipient updated = new Recipient(
reqRecipient.getName(),
"new.email@example.com",
reqRecipient.getOrder(),
reqRecipient.getDocuments(),
reqRecipient.getEmailGroup(),
reqRecipient.getAttributes());
recipientCollection.add(updated);
} else {
recipientCollection.add(reqRecipient);
}
}
DocumentCollection docs2 = new DocumentCollection();
// Viewer recipient: no signature, only view the document
docs2.add(new Document(documentId2, secondRecipientRole, viewAction));
Attribute viewerAttribute = Attribute.viewer("Please review", "Document review", false, null, null, null, null);
Recipient recipient2 = new Recipient("Jane Smith", "jane.smith@example.com", 2, docs2, null, viewerAttribute);

RecipientCollection recipients = new RecipientCollection();
recipients.add(recipient1);
recipients.add(recipient2);

GeneralReminder generalReminder = new GeneralReminder(1, 5, 3);

// Send PUT request
DocumentGroupRecipientsPutRequest putRequest = new DocumentGroupRecipientsPutRequest(
recipientCollection,
new CcCollection()).withDocumentGroupId(documentGroupId);
recipients,
new CcCollection(),
expirationDays,
generalReminder,
recipientOrder
).withDocumentGroupId(documentGroupId);

DocumentGroupRecipientsPutResponse putResponse = (DocumentGroupRecipientsPutResponse) client.send(putRequest)
.getResponse();
System.out.println("Updated email: " + putResponse.getData().getRecipients().get(0).getEmail());
System.out.println("==== PUT ====");
System.out.println("Updated recipients:");
putResponse.getData().getRecipients().forEach(r -> {
System.out.println(" Name: " + r.getName() + ", Email: " + r.getEmail());
});
if (putResponse.getData().getGeneralExpirationDays() != null) {
System.out.println("General Expiration Days: " + putResponse.getData().getGeneralExpirationDays());
}
if (putResponse.getData().getGeneralReminder() != null) {
com.signnow.api.documentgroup.response.data.data.GeneralReminder responseReminder = putResponse.getData().getGeneralReminder();
System.out.println("General Reminder - After: " + responseReminder.getRemindAfter()
+ ", Before: " + responseReminder.getRemindBefore()
+ ", Repeat: " + responseReminder.getRemindRepeat());
}
if (putResponse.getData().getOrderType() != null) {
System.out.println("Order Type: " + putResponse.getData().getOrderType());
}

// GET /v2/document-groups/{document_group_id}/recipients
System.out.println("==== GET ====");
DocumentGroupRecipientsGetRequest getRequest = new DocumentGroupRecipientsGetRequest()
.withDocumentGroupId(documentGroupId);
DocumentGroupRecipientsGetResponse getResponse = (DocumentGroupRecipientsGetResponse) client.send(getRequest)
.getResponse();
System.out.println("Recipients:");
getResponse.getData().getRecipients().forEach(r -> {
System.out.println(" Name: " + r.getName() + ", Email: " + r.getEmail());
});
if (getResponse.getData().getGeneralExpirationDays() != null) {
System.out.println("General Expiration Days: " + getResponse.getData().getGeneralExpirationDays());
}
if (getResponse.getData().getGeneralReminder() != null) {
com.signnow.api.documentgroup.response.data.data.GeneralReminder responseReminder = getResponse.getData().getGeneralReminder();
System.out.println("General Reminder - After: " + responseReminder.getRemindAfter()
+ ", Before: " + responseReminder.getRemindBefore()
+ ", Repeat: " + responseReminder.getRemindRepeat());
}
if (getResponse.getData().getOrderType() != null) {
System.out.println("Order Type: " + getResponse.getData().getOrderType());
}
} catch (SignNowApiException e) {
System.out.println("ERROR: " + e.getMessage());
}
}

private static Recipient convertRecipient(
com.signnow.api.documentgroup.response.data.data.Recipient responseRecipient) {
ObjectMapper mapper = new ObjectMapper();
try {
String json = mapper.writeValueAsString(responseRecipient);
Recipient recipient = mapper.readValue(json, Recipient.class);

return new Recipient(
recipient.getName(),
recipient.getEmail(),
recipient.getOrder(),
recipient.getDocuments(),
recipient.getEmailGroup(),
recipient.getAttributes());

} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
}
Loading
Loading