Download Documents
This page describes functionality for the older eSignature SOAP API. See How to download envelope documents for more information on this topic in the more actively-supported eSignature REST API documentation.
In this example we will cover the different methods that you can use to retrieve documents from Docusign. You should already be comfortable with working with webservices to follow along here. There will be code samples displayed in both C# (using .net 3.5) and PHP, but you should already know how to get your local proxy class setup and your credentials entered.
The documents
Once you send a Docusign envelope, and the Recipients sign it, the next step is usually to retrieve the signed documents. While you can leave them in the Docusign account, many implementers want their systems to keep copies locally. Additionally, Docusign provides a document called the Envelope Certificate that displays key data about the signing ceremony, and this document is often kept locally along with the signed documents to provide evidence of the transaction.
RequestPDF
Step 1. Get envelope PDF object
The first method we’ll discuss is the RequestPDF method. This method takes an EnvelopeID as a parameter, and returns a structure that contains the EnvelopeID and a PDF file. The PDF File contains the entire contents of the envelope, so if you sent in an envelope with five different documents in it, the resulting PDF will contain all five documents in order.
The right column shows an example of using the RequestPDF method.
Step 2. Store envelope
Step 2. Store envelope
Now that you have the EnvelopePDF object, you can access the raw bytes via the EnvelopePDF.PDFBytes accessor and write them out to a file ( or a database blob field, etc)
Step 3. Get envelope contents as individual documents
The RequestDocumentPDFs method is used when you want to get all of the Envelope’s contents back as individual documents. This is very useful when you have a package of documents that are signed and then need to be routed to different departments after signing. For example, using the Auto Insurance example, you might have an Electronic Funds Transfer authorization form in the Envelope along with the Insurance Application, and post signing you need to send the EFT form to finance and the Application to wherever Insurance applications go to.
This method also includes the Envelope Certificate, so if you want this you have to use this method rather than RequestPDF. The returned data from this call is a DocumentPDFs object, which contains the EnvelopeID and an array of DocumentPDF objects – 1 for each original document, plus the Envelope Certificate.
Assuming that you already have your api proxy setup, here’s the code:
Step 4. Store documents
With the DocumentPDFs object, you will need to iterate the array of DocumentPDF objects, and access the PDFBytes property on each DocumentPDF. You will also see some other properties there – like ‘Name’, which will contain the name of the file when it was sent in the envelope. For the Envelope Certificate, the Name will be ‘Summary’. Remember that the name will be whatever it was set to, so if you are saving it out to the filesystem you will need to add the ‘pdf’ extension to the Name.
You will also see a couple of properties – currently DocumentID and DocumentType – that will not be populated. This is because the DocumentPDFs object is used as the return value both for the RequestDocumentPDFs method and the RequestDocumentPDFsEx method.
RequestDocumentPDFsEx
This method is a variant of the RequestDocumentPDFs method that returns additional elements in the response. The exact elements that can be returned will change over time, so if you are using this method you need to be sure that your code won’t break if it encounters an unexpected property here. Currently the DocumentID and DocumentType properties are being returned but there may be additional elements here in the future. Also note that these additional elements return data that would have been supplied at the time the envelope was created. If you did not specifically add this data to the envelope, it will not be there when you call this method.
Download source code
You can download the source code for this example and all other code examples from GitHub: