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

Before you begin, import the Node.js module:

function (factory) {            
    module.exports = factory(require(''adobe-sign-sdk'), require('fs'));    
}

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:

//Let's load the modules
(
    function (factory) {    
        module.exports = factory(require('rest-api-sdk/src/index'), require("fs"));
    }
    (function (AdobeSignSdk, fs) 
    {   
        (function TransientSample() {
            //Get the API context        
            var context = new AdobeSignSdk.Context();   
            
            //Initialize the transient document API
            var transientDocumentsApi = new AdobeSignSdk.TransientDocumentsApi(context);   
     
            //Pass the access token. See the Getting Started section to know more.
            var headerParams = {"accessToken": "3AAABLblNotTHErEALTokenAYplDlCDFrFAVPhDlOt"};        
            
            //We will upload a PDF file
            var fileBytes = fs.readFileSync('MySample.pdf');        
            var buffer = new Buffer(fileBytes);        
            
            var opts = {};        
            opts["mimeType"] = "application/pdf";
        
            //Invoke the API
            transientDocumentsApi.createTransientDocument(headerParams, 'MySample.pdf', buffer, opts)                
                                 .then(function (transientDocumentCreationResponse) {                    
                                        console.log("The Transient Id is" + transientDocumentCreationResponse.getTransientDocumentId());                
                                 })                
                                 .catch(function (apiError) {                    
                                        console.log(apiError);                
                                 });    
            })();
    }
));

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.


A few parameters use in this example 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:

//Set the context        
var context = new AdobeSignSdk.Context();        

//Keep the Transient Document ID handy (see the previous example)       
var transientDocumentId = "3AAABLbNOTREALDOCUMENTIDsY7snzhnIDm630L";        

//Initialize the Agreements API        
var agreementsApi = new AdobeSignSdk.AgreementsApi(context);        
var agreementsModel = AdobeSignSdk.AgreementsModel;        

//Get recipient set info        
//Create an array of recipients from list of email ids.        
var recipientSetMemberInfos = [];        
var userEmails = ["somerecepients@gmail.com"];        

for (var i = 0; i < userEmails.length; i++) {            
    var recipientInfo = new agreementsModel.RecipientInfo();            
    recipientInfo.setEmail(userEmails[i]);            
    recipientSetMemberInfos.push(recipientInfo);        
}        

//Create recipient set info        
var recipientSetInfo = new agreementsModel.RecipientSetInfo();        
recipientSetInfo.setRecipientSetMemberInfos(recipientSetMemberInfos);        
recipientSetInfo.setRecipientSetRole(agreementsModel.RecipientSetInfo.RecipientSetRoleEnum.SIGNER);        
recipientSetInfo.setRecipientSetName("fjenning@adobe.com");       

var recipientSetInfos = [];        
recipientSetInfos.push(recipientSetInfo);        

//Get file info and create a list of file info        
var fileInfo = new agreementsModel.FileInfo();        
fileInfo.setTransientDocumentId(transientDocumentId); 
       
var fileInfos = [];        
fileInfos.push(fileInfo);        

//Get document creation info        
//Create document creation info from the file info object        
var documentCreationInfo = new agreementsModel.DocumentCreationInfo();        
documentCreationInfo.setName("MyAgreement");        
documentCreationInfo.setFileInfos(fileInfos);        
documentCreationInfo.setRecipientSetInfos(recipientSetInfos);        
documentCreationInfo.setSignatureType(agreementsModel.DocumentCreationInfo.SignatureTypeEnum.ESIGN);        
documentCreationInfo.setSignatureFlow(agreementsModel.DocumentCreationInfo.SignatureFlowEnum.SENDER_SIGNATURE_NOT_REQUIRED);        

//Get agreement creation info        
var agreementCreationInfo = new agreementsModel.AgreementCreationInfo();        
agreementCreationInfo.setDocumentCreationInfo(documentCreationInfo);  
      
var headerParams = {"accessToken": "3AAABLNOTTHEREALTOKENn0RivpHP7q"};        

//Make API call to create agreement        
agreementsApi.createAgreement(headerParams, agreementCreationInfo)                
             .then(function (agreementCreationResponse) {                    
                    console.log("Agreement created for Id " + agreementCreationResponse.getAgreementId());                
             })                
             .catch(function (apiError) {                    
                    console.log(apiError);                
             });



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:

var fileInfo = new agreementsModel.FileInfo();        
fileInfo.setTransientDocumentId(transientDocumentId);

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

var fileInfo = new agreementsModel.FileInfo();     
fileInfo.setLibraryDocumentId(transientDocumentId);