download-the-agreement

Once an agreement is signed, your application can retrieve the signed copy of the all associated documents and store them locally:

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

//Know the Agreement ID        
var agreementId = "3AAABLblqNOTHEREALAGREEMENTID2nbK9W5PKAoWm";        

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

var headerParams = {"accessToken": "3AAABLblqZhNOTTHEREALTOKENK1ps2CC"};        

//Get all the documents for the agreement        
agreementsApi.getAllDocuments(headerParams, agreementId, null,  null,  null)                
             .then(function (agreementDocuments) {                    
                    var agreementDocumentsList = agreementDocuments.getDocuments();                    
                    var promises = [];                    

                    for (var i = 0; i < agreementDocumentsList.length; i++) {                        
                        var document = agreementDocumentsList[i];  
                      
                        //Download all the documents of the given agreement                        
                        promises.push(AgreementUtils.downloadDocuments(agreementId, document.getDocumentId())                                
                                .then(function (docStream) {                                    
                    
                                        //Generate a running file name for storing locally.                                    
                                        var fileName = document.getName() + "_" + Date.now().toString() + ".pdf";                                    
                                        var agreementDocumentsFolderPath = path.join(ApiUtils.getOutputFolderPath(), Constants.AGREEMENT_DOCUMENT);                                    
                    
                                        //Save the documents to file.
                                        if (docStream != null) {                                        
                                            //SAVE TO FILE                                                                                
                                        }                                
                        }));                    
                    }                
             })                
             .catch(function (apiError) {                    
                    console.log(apiError);                
             });