/// <summary> /// GetDocumentByName: receives an envelope ID and a document name and returns the document as MemoryStream from the corresponding envelope. /// </summary> /// <param name="accountID">Account ID, as string</param> /// <param name="envelopeID">Envelope ID, as string</param> /// <param name="docName">Document name, as string</param> /// <returns> /// MemoryStream as document with docName in envelope with EnvelopeID /// </returns> public static MemoryStream GetDocumentByName(string accountID, string envelopeID, string docName) { MemoryStream docStream = null; // |EnvelopesApi| contains methods related to envelopes and envelope recipients EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeDocumentsResult docsList = envelopesApi.ListDocuments(accountID, envelopeID); // read how many documents are in the envelope int docCount = docsList.EnvelopeDocuments.Count; // loop through the envelope's documents, search for document with DocName and download it. for (int i = 0; i < docCount; i++) { if (docsList.EnvelopeDocuments[i].Name.Equals(docName)) { // GetDocument() API call returns a MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(accountID, envelopeID, docsList.EnvelopeDocuments[i].DocumentId); break; } } return(docStream); }
public void GetDocument_CorrectInputParameters_ReturnMemoryStream() { CreateEnvelopeMethod.CreateEnvelope_CorrectAccountIdAndEnvelopeDefinition_ReturnEnvelopeSummary(ref _testConfig); EnvelopeDocumentsResult docsList = _envelopesApi.ListDocuments(_testConfig.AccountId, _testConfig.EnvelopeId); Assert.IsNotNull(docsList?.EnvelopeId); int docCount = docsList.EnvelopeDocuments.Count; for (int i = 0; i < docCount; i++) { Assert.IsNotNull(docsList?.EnvelopeDocuments[i]?.DocumentId); MemoryStream docStream = (MemoryStream)_envelopesApi.GetDocument( _testConfig.AccountId, _testConfig.EnvelopeId, docsList.EnvelopeDocuments[i].DocumentId); Assert.IsNotNull(docStream); string filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; var fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); Assert.IsNotNull(filePath); } }
protected void Page_Load(object sender, EventArgs e) { ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi"); Configuration.Default.ApiClient = apiClient; Configuration.Default.DefaultHeader.Remove("X-DocuSign-Authentication"); Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", envelope.dsAuthHeader); EnvelopesApi envelopesApi2 = new EnvelopesApi(); EnvelopeDocumentsResult docs = envelopesApi2.ListDocuments(envelope.dsAccountId, envelope.dsEnvelopeId); string docID = docs.EnvelopeDocuments[0].DocumentId; MemoryStream docStream = (MemoryStream)envelopesApi2.GetDocument(envelope.dsAccountId, envelope.dsEnvelopeId, docID); string filePath = null; filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; FileStream fs = null; fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); WebClient client = new WebClient(); Byte[] buffer = client.DownloadData(filePath); if (buffer != null) { Response.ContentType = "application/pdf"; Response.AddHeader("content-length", buffer.Length.ToString()); Response.BinaryWrite(buffer); } }
public ActionResult Create(string docSelect) { // Data for this method // docSelect -- argument var accessToken = _requestItemsService.User.AccessToken; var basePath = _requestItemsService.Session.BasePath + "/restapi"; var accountId = _requestItemsService.Session.AccountId; var envelopeId = _requestItemsService.EnvelopeId; var apiClient = new ApiClient(basePath); // documents data for the envelope. See example EG006 var envelopesApi = new EnvelopesApi(apiClient); apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); EnvelopeDocumentsResult results = envelopesApi.ListDocuments(accountId, envelopeId); List <EnvelopeDocItem> envelopeDocItems = new List <EnvelopeDocItem> { new EnvelopeDocItem { Name = "Combined", Type = "content", DocumentId = "combined" }, new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" } }; foreach (EnvelopeDocument doc in results.EnvelopeDocuments) { envelopeDocItems.Add(new EnvelopeDocItem { DocumentId = doc.DocumentId, Name = doc.DocumentId == "certificate" ? "Certificate of completion" : doc.Name, Type = doc.Type }); } bool tokenOk = CheckToken(3); if (!tokenOk) { // We could store the parameters of the requested operation // so it could be restarted automatically. // But since it should be rare to have a token issue here, // we'll make the user re-enter the form data after // authentication. _requestItemsService.EgName = "Home"; return(Redirect("/ds/mustAuthenticate")); } FileStreamResult result = DoWork(accessToken, basePath, accountId, envelopeId, envelopeDocItems, docSelect); return(result); }
public EnvelopeDocumentsResult ListEnvelopeDocuments(String accountId, String envelopeId) { EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeDocumentsResult docsList = envelopesApi.ListDocuments(accountId, envelopeId); // print the JSON response Console.WriteLine("EnvelopeDocumentsResult:\n{0}", JsonConvert.SerializeObject(docsList)); return(docsList); }
private void ObterDocumentos(string idEnvelope) { EnvelopesApi envelopeApi = new EnvelopesApi(ApiService.ApiClient.Configuration); EnvelopeDocumentsResult results = envelopeApi.ListDocuments(ApiService.AccountID, idEnvelope); foreach (EnvelopeDocument doc in results.EnvelopeDocuments) { System.IO.Stream documentoPdf = envelopeApi.GetDocument(ApiService.AccountID, idEnvelope, doc.DocumentId); StorageHelper.UploadFileFromStream(Config, documentoPdf, $"`{idEnvelope}{doc.Name}.pdf"); } }
} // end listEnvelopesTest() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void listDocumentsAndDownloadTest() { // Enter your DocuSign credentials below. Note: You only need a DocuSign account to SEND documents, // signing is always free and signers do not need an account. string username = "******"; string password = "******"; // provide a valid envelope ID from your account. string envelopeId = "[ENVELOPE_ID]]"; // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi) configureApiClient("https://demo.docusign.net/restapi"); //=========================================================== // Step 1: Login() //=========================================================== // call the Login() API which sets the user's baseUrl and returns their accountId string accountId = loginApi(username, password); //=========================================================== // Step 2: List Envelope Document(s) //=========================================================== // |EnvelopesApi| contains methods related to envelopes and envelope recipients EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeDocumentsResult docsList = envelopesApi.ListDocuments(accountId, envelopeId); // print the JSON response Console.WriteLine("EnvelopeDocumentsResult:\n{0}", JsonConvert.SerializeObject(docsList)); //=========================================================== // Step 3: Download Envelope Document(s) //=========================================================== // read how many documents are in the envelope int docCount = docsList.EnvelopeDocuments.Count; string filePath = null; FileStream fs = null; // loop through the envelope's documents and download each doc for (int i = 0; i < docCount; i++) { // GetDocument() API call returns a MemoryStream MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(accountId, envelopeId, docsList.EnvelopeDocuments[i].DocumentId); // let's save the document to local file system filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); Console.WriteLine("Envelope Document {0} has been downloaded to: {1}", i, filePath); } } // end listDocumentsAndDownloadTest()
public void GetDocumentListDownloadDocumentTest() { try { RequestSignatureOnADocumentTest(); Assert.IsNotNull(TestConfig.AccountId); Assert.IsNotNull(TestConfig.EnvelopeId); EnvelopesApi envelopesApi = new EnvelopesApi(); DateTime fromDate = DateTime.UtcNow; fromDate = fromDate.AddDays(-5); EnvelopesApi.ListStatusChangesOptions ops = new EnvelopesApi.ListStatusChangesOptions() { count = "10", fromDate = fromDate.ToString() }; EnvelopesInformation eInfo = envelopesApi.ListStatusChanges(TestConfig.AccountId, ops); Assert.IsNotNull(eInfo); Assert.IsTrue(!string.IsNullOrEmpty(eInfo.ResultSetSize) && int.Parse(eInfo.ResultSetSize) > 0); string envelopeId = eInfo.Envelopes[0].EnvelopeId; EnvelopeDocumentsResult envDocsResult = envelopesApi.ListDocuments(TestConfig.AccountId, envelopeId); Assert.IsNotNull(envDocsResult); int docCount = envDocsResult.EnvelopeDocuments.Count; Assert.IsTrue(docCount > 0); MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(TestConfig.AccountId, envelopeId, envDocsResult.EnvelopeDocuments[0].DocumentId); string filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; FileStream fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); System.Diagnostics.Process.Start(filePath); } catch (DocuSign.eSign.Client.ApiException apiEx) { Assert.IsNotNull(apiEx.ErrorCode); Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message)); Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message); } }
// ***DS.snippet.0.start private (EnvelopeDocumentsResult results, EnvelopeDocuments envelopeDocuments) DoWork( string accessToken, string basePath, string accountId, string envelopeId) { // Data for this method // accessToken // basePath // accountId // envelopeId var apiClient = new ApiClient(basePath); apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); var envelopesApi = new EnvelopesApi(apiClient); EnvelopeDocumentsResult results = envelopesApi.ListDocuments(accountId, envelopeId); // Prepare and save the envelopeId and its list of documents in the session so // they can be used in example 7 (download a document) List <EnvelopeDocItem> envelopeDocItems = new List <EnvelopeDocItem> { new EnvelopeDocItem { Name = "Combined", Type = "content", DocumentId = "combined" }, new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" } }; foreach (EnvelopeDocument doc in results.EnvelopeDocuments) { envelopeDocItems.Add(new EnvelopeDocItem { DocumentId = doc.DocumentId, Name = doc.DocumentId == "certificate" ? "Certificate of completion" : doc.Name, Type = doc.Type }); } EnvelopeDocuments envelopeDocuments = new EnvelopeDocuments { EnvelopeId = envelopeId, Documents = envelopeDocItems }; return(results, envelopeDocuments); }
public void DownloadEnvelopeDocuments(String accountId, EnvelopeDocumentsResult docsList) { EnvelopesApi envelopesApi = new EnvelopesApi(); String filePath = String.Empty; FileStream fs = null; for (int i = 0; i < docsList.EnvelopeDocuments.Count; i++) { // GetDocument() API call returns a MemoryStream MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(accountId, docsList.EnvelopeId, docsList.EnvelopeDocuments[i].DocumentId); // let's save the document to local file system filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); Console.WriteLine("Envelope Document {0} has been downloaded to: {1}", i, filePath); } }
public void JwtListDocumentsAndDownloadTest() { JwtRequestSignatureOnDocumentTest(); // |EnvelopesApi| contains methods related to envelopes and envelope recipients EnvelopesApi envelopesApi = new EnvelopesApi(testConfig.ApiClient.Configuration); EnvelopeDocumentsResult docsList = envelopesApi.ListDocuments(testConfig.AccountId, testConfig.EnvelopeId); Assert.IsNotNull(docsList); Assert.IsNotNull(docsList.EnvelopeId); //=========================================================== // Step 3: Download Envelope Document(s) //=========================================================== // read how many documents are in the envelope int docCount = docsList.EnvelopeDocuments.Count; string filePath = null; FileStream fs = null; // loop through the envelope's documents and download each doc for (int i = 0; i < docCount; i++) { Assert.IsNotNull(docsList.EnvelopeDocuments[i].DocumentId); // GetDocument() API call returns a MemoryStream MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(testConfig.AccountId, testConfig.EnvelopeId, docsList.EnvelopeDocuments[i].DocumentId); Assert.IsNotNull(docStream); // let's save the document to local file system filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; fs = new FileStream(filePath, FileMode.Create); docStream.Seek(0, SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); Assert.IsNotNull(filePath); } }
/// <summary> /// Gets a list of all the documents for a specific envelope /// </summary> /// <param name="accessToken">Access Token for API call (OAuth)</param> /// <param name="basePath">BasePath for API calls (URI)</param> /// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param> /// <param name="envelopeId">The required envelopeId</param> /// <returns>An object containing information about all the documents in the envelopes</returns> public static EnvelopeDocuments GetDocuments(string accessToken, string basePath, string accountId, string envelopeId) { var apiClient = new ApiClient(basePath); apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); EnvelopesApi envelopesApi = new EnvelopesApi(apiClient); EnvelopeDocumentsResult results = envelopesApi.ListDocuments(accountId, envelopeId); List <EnvelopeDocItem> envelopeDocItems = new List <EnvelopeDocItem> { new EnvelopeDocItem { Name = "Combined", Type = "content", DocumentId = "combined" }, new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" } }; foreach (EnvelopeDocument doc in results.EnvelopeDocuments) { envelopeDocItems.Add(new EnvelopeDocItem { DocumentId = doc.DocumentId, Name = doc.DocumentId == "certificate" ? "Certificate of completion" : doc.Name, Type = doc.Type }); } EnvelopeDocuments envelopeDocuments = new EnvelopeDocuments { EnvelopeId = envelopeId, Documents = envelopeDocItems }; return(envelopeDocuments); }
public string RequestSignedDocument(string envelopeId) { try { if (!_canExecuteRequest) { throw new Exception("Failed to retrieve Credentials from Credential store"); } if (Utility.IsEventLogged) { Utility.LogAction("Request signed document"); } string authHeader = "{\"Username\":\"" + _email + "\", \"Password\":\"" + _password + "\", \"IntegratorKey\":\"" + _integratorKey + "\"}"; DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader); EnvelopesApi envelopesApi = new EnvelopesApi(); string accountId = (!string.IsNullOrEmpty(Utility.DocuSignAccountID)) ? Utility.DocuSignAccountID : GetAccountID(); if (Utility.IsEventLogged) { Utility.LogAction("Sending request to get the envelope"); } Envelope envelope = envelopesApi.GetEnvelope(accountId, envelopeId); envelopesApi = new EnvelopesApi(); byte[] signedDocArray = null; if (envelope.Status.ToLower() == "completed") { if (Utility.IsEventLogged) { Utility.LogAction("Sending request to get the list of documents"); } EnvelopeDocumentsResult docsList = envelopesApi.ListDocuments(accountId, envelopeId); if (docsList.EnvelopeDocuments.Count > 0) { if (Utility.IsEventLogged) { Utility.LogAction("Sending request to get the signed document"); } MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(accountId, docsList.EnvelopeId, docsList.EnvelopeDocuments[0].DocumentId); signedDocArray = docStream.ToArray(); //SaveToLocation(signedDocArray); } } return(signedDocArray != null?Convert.ToBase64String(signedDocArray) : ""); } catch (Exception ex) { Utility.LogAction("sending request to get the signed documet failed with exception: " + ex.Message); return(string.Empty); } }
public async Task WebhookDocuSignResponse(HttpRequestMessage request) { string directorypath = HttpContext.Current.Server.MapPath("~/App_Data/" + "Files/"); if (!Directory.Exists(directorypath)) { Directory.CreateDirectory(directorypath); } // StringBuilder sb = new StringBuilder(); // sb.Append("log something"); // flush every 20 seconds as you do it // File.AppendAllText(directorypath + "log.txt", sb.ToString()); // to check the xml data pushed by docusign to our listener. XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(request.Content.ReadAsStreamAsync().Result); // sb.Append(xmldoc.InnerXml); // File.AppendAllText(directorypath + "XMLlog.txt", sb.ToString()); // sb.Clear(); var mgr = new XmlNamespaceManager(xmldoc.NameTable); mgr.AddNamespace("a", "http://www.docusign.net/API/3.0"); XmlNode envelopeStatus = xmldoc.SelectSingleNode("//a:EnvelopeStatus", mgr); XmlNode envelopeId = envelopeStatus.SelectSingleNode("//a:EnvelopeID", mgr); XmlNode status = envelopeStatus.SelectSingleNode("./a:Status", mgr); string envId = envelopeId.InnerText; if (envelopeId != null) { //*************** need to fetch the return url from envelopeid so that url can be dynamic not fixed. string retUrl = GetReturnUrl(envId); } // Loop through the DocumentPDFs element, storing each signed document. //XmlNode docs = xmldoc.SelectSingleNode("//a:DocumentPDFs", mgr); //foreach (XmlNode doc in docs.ChildNodes) //{ // string documentName = doc.ChildNodes[0].InnerText; // pdf.SelectSingleNode("//a:Name", mgr).InnerText; // string documentId = doc.ChildNodes[2].InnerText; // pdf.SelectSingleNode("//a:DocumentID", mgr).InnerText; // string byteStr = doc.ChildNodes[1].InnerText; // pdf.SelectSingleNode("//a:PDFBytes", mgr).InnerText; // byte[] bytArray = Encoding.ASCII.GetBytes(byteStr); // // System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("~/Documents/" + envelopeId.InnerText + "_" + documentId + "_" + documentName), byteStr); // System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("~/Documents/" + envelopeId.InnerText + "_" + documentId + "_" + documentName), System.Convert.ToBase64String(bytArray)); //} if (status.InnerText == "Completed") { XmlNode recipientStatus = xmldoc.SelectSingleNode("//a:RecipientStatus", mgr); XmlNode UserName = recipientStatus.SelectSingleNode("//a:UserName", mgr); // purge the envelope if status is completed. EnvelopesApi obj = new EnvelopesApi(); ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi"); DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient; //Verify Account Details string accountId = loginApi("", ""); /// String filePath = String.Empty; // FileStream fs = null; PayloadData payLoadData = new PayloadData(); payLoadData.DocumentBase64 = ""; payLoadData.UserNameFile = UserName.InnerText; string DocumentBase64 = ""; EnvelopeDocumentsResult docsList = obj.ListDocuments(accountId, envId); for (int i = 0; i < docsList.EnvelopeDocuments.Count; i++) { if (docsList.EnvelopeDocuments[i].Type == "content") { MemoryStream docStream = (MemoryStream)obj.GetDocument(accountId, envId, docsList.EnvelopeDocuments[i].DocumentId); byte[] fileData = docStream.ToArray(); payLoadData.DocumentBase64 = System.Convert.ToBase64String(fileData); } } // method to post data to caller api i.e signed document without storing it using (var client = new HttpClient()) { // as of now the url is hardcoded we can get it from above call of geturl. // client.PostAsync() var res = await client.PostAsync("http://localhost:52427/api/DocusignDemoo/ReciveSignedDoc", new StringContent(JsonConvert.SerializeObject(payLoadData), Encoding.UTF8, "application/json")); try { res.EnsureSuccessStatusCode(); //res.Result.EnsureSuccessStatusCode(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } //B return Ok(); // let's save the document to local file system //filePath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf"; //fs = new FileStream(filePath, FileMode.Create); //docStream.Seek(0, SeekOrigin.Begin); //docStream.CopyTo(fs); //fs.Close(); // MemStream ms = FileStream().Save() //Envelope envInfo = obj.GetEnvelope(accountId, envId); //envInfo.PurgeState = "documents_and_metadata_queued"; //envInfo.EnvelopeId = envId; //// set envelope status voided forcefully to purge. //envInfo.Status = "voided"; //EnvelopeUpdateSummary envelopeUpdateSummary = obj.Update(accountId, envInfo.EnvelopeId, envInfo, null); } }