create-an-agreement

Your CRM system or document management system can send/upload documents for signing either automatically or through user-initiated actions. When the document gets signed by all the parties, a PDF copy of the signed document(agreement) can be retrieved by your application.

Uploading a document

To upload a document and get the document ID from the Sign Server, use the TransientDocumentsApi class.

Let's create a transient document and get the ID:

//Create a File object      
File inputFile = new File ("MyDocument.pdf");

//Populate the headers
//Note that MultivaluedMap is part of javax.ws.rs.core package
//Note that MultivaluedMapImpl is part of com.sun.jersey.core.util package
MultivaluedMap headers = new MultivaluedMapImpl();    
//Add headers    
String ACCESS_TOKEN_KEY= "Access-Token";  
String X_API_USER_KEY = "x-api-user";
headers.put(ACCESS_TOKEN_KEY, "hajUhhsNottheRealTokenjKh");    
headers.put(X_API_USER_KEY, "me@mycomp.com");

//Create a transient document.      
TransientDocumentResponse  transientDocumentResponse = transientDocumentsApi.createTransientDocument(headers, file.getAbsoluteFile(), "MyDocument.pdf", "application/pdf");

//Get the transient document ID
String documentID = transientDocumentResponse.getTransientDocumentId();

//Print the transient document ID
System.out.println("Transient Document ID: "+documentID);

The document ID that you get through the getTransientDocumentId() method is  the unique identifier of the uploaded document that can be used to create an Agreement or a Widget.


The parameters are:

  • accessToken - The OAuth Access Token with any of the following scopes - agreement_write, agreement_send, widget_write, or library_write
  • file - The file part of the multipart request for document upload. You can upload only one file at a time.
  • xApiUser - The user ID or email of API caller using the account or group token in the format userid:{userId} OR email:{email}. If it is not specified, then the caller is inferred from the token.
  • fileName - A name for the document being uploaded.
  • mimeType - The mime type of the document being uploaded. If not specified, then the mime type is derived from the File object.

The document uploaded through this call is termed as a transient document since it is available only for 7 days after the upload. 

You can only upload one file at a time through this request.

Sending the document

Once you have uploaded the document, send the document to all the related parties for signing. For this to happen, you need to create an 'agreement' from the transient document ID you got from the previous section.

To create an Agreement, use the AgreementsApi class:

//Create an array of recipients from list of email ids.    
List recipientSetMemberInfos = new ArrayList();    
for (String userEmail : userEmails){      
    RecipientInfo recipientInfo = new RecipientInfo();      
    recipientInfo.setEmail(userEmail);      
    recipientSetMemberInfos.add(recipientInfo);    
}

//Create recipient set info    
RecipientSetInfo recipientSetInfo  = new RecipientSetInfo();   
recipientSetInfo.setRecipientSetMemberInfos(recipientSetMemberInfos);   
//Set the role of the recipient 
recipientSetInfo.setRecipientSetRole(RecipientSetInfo.RecipientSetRoleEnum.SIGNER);    
List recipientSetInfos =  new ArrayList();    
recipientSetInfos.add(recipientSetInfo);
      
//Create file info object using document id and name    
FileInfo fileInfo = new FileInfo();
fileInfo.setTransientDocumentId(documentId);

//Get file info and create a list of file info      
List fileInfos = new ArrayList();      
fileInfos.add(fileInfo);
      
//Get document creation info using library document id      
DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo();    
documentCreationInfo.setName(agreementName);    
documentCreationInfo.setFileInfos(fileInfos);    
documentCreationInfo.setRecipientSetInfos(recipientSetInfos);    
documentCreationInfo.setSignatureType(DocumentCreationInfo.SignatureTypeEnum.ESIGN);    
documentCreationInfo.setSignatureFlow(DocumentCreationInfo.SignatureFlowEnum.SENDER_SIGNATURE_NOT_REQUIRED);
      
//Get agreement creation info      
AgreementCreationInfo agreementCreationInfo = new AgreementCreationInfo();    
agreementCreationInfo.setDocumentCreationInfo(documentCreationInfo);  
//For a simple case, we don't need to set the interactive options  
agreementCreationInfo.setOptions(null);
      
//Populate the headers
//Note that MultivaluedMap is part of javax.ws.rs.core package
//Note that MultivaluedMapImpl is part of com.sun.jersey.core.util package
MultivaluedMap headers = new MultivaluedMapImpl(); 
String ACCESS_TOKEN_KEY= "Access-Token";  
String X_API_USER_KEY = "x-api-user";   
headers.put(ACCESS_TOKEN_KEY, "hajUhhsNottheRealTokenjKh");    
headers.put(X_API_USER_KEY, "me@mycomp.com");

//Make the API call to create an Agreement      
AgreementCreationResponse agreementCreationResponse = agreementsApi.createAgreement(headers, agreementCreationInfo);

//Get the Agreement ID
String agreementID = agreementCreationResponse.getAgreementId();

//Print the Agreement ID
System.out.println("Agreement ID: "+agreementID);

Understand the following key attributes:

  • recipientSetRole - The role of the recipient. The possible values are APPROVER, DELEGATE_TO_APPROVER, DELEGATE_TO_SIGNER, and SIGNER.
  • signatureType - The type of signature you would like to request. The possible values are ESIGN and WRITTEN.
  • signatureFlow - The workflow you would like to use - whether the sender needs to sign before the recipient, after the recipient, or not at all. The possible values are SENDER_SIGNATURE_NOT_REQUIRED, SENDER_SIGNS_LAST, SENDER_SIGNS_FIRST, SEQUENTIAL or PARALLEL. 

 

The returned agreeemnt ID must be used to refer to the agreement in all subsequent API calls. This ID must be used to retrieve up-to-date status of the agreement either by polling or when Adobe Sign notifies your application of any status change.

Sending agreements from library

Instead of uploading a document everytime when you need to create an agreement, you can send an agreement using the users' library document.

Note that in the previous example, we invoked the setTransientDocumentId() method to set the document ID:

//Create file info object using document id and name    
FileInfo fileInfo = new FileInfo();
fileInfo.setTransientDocumentId(documentId);

To create an Agreement from the first library document of the user, use the setLibraryDocumentId() method:

FileInfo fileInfo = new FileInfo();
fileInfo.setLibraryDocumentId(documentId);