Get Document Data From DocuSign

We learned how to send a PDF file to other people for signing in the last article.

In this blog, we’ll get the data from the document and see if it’s been signed by people. We also need an access token for doing this task. If you want to know how to get an access token from DocuSign then click here . We started this journey from the scratch. If you want to start from scratch then click here.

Get Started:

Step 1:

Specify the necessary keys in the appsettings.json file. Click here to get the DocuSign keys.

"DocuSign": {
    "IntegrationKey": "fc81131e-XXXX-XXXX-XXXX-0dbfc94e3af7",
    "UserId": "29c410f7-XXXX-XXXX-XXXX-1a4fc813defd",
    "AuthServer": "account-d.docusign.com",
    "RSAPrivateKeyFile": "private.key",
    "JWTLifeTime": "1",
    "BaseURI": "https://demo.docusign.net",
    "AccountId": "e2f2e355-XXXX-XXXX-XXXX-764d6994f8c2",
}

Step 2:

We need an EnvelopId and AccessToken in the API request. (When you transmit the document for signing to another person, keep in mind that the EnvelopId will be returned in the response.) Create a GetDocumentDataRequest class and declare EnvelopId and AccessToken in it.

public class GetDocumentDataRequest
{
     public string EnvelopId { get; set; }

     public string AccessToken { get; set; }
}

Step 3:

Define the method in the IDocuSignService interface class.

Task<Envelope> GetDocumentData(GetDocumentDataRequest request);

//Where 'Envelope' imported from 'using DocuSign.eSign.Model;'

Step 4:

Add method in the DocuSignService class.

public async Task<Envelope> GetDocumentData(GetDocumentDataRequest request)
 {
     Envelope envelopeData = new Envelope();

     if (request.EnvelopId != string.Empty && request.AccessToken != string.Empty)
     {
         var client = await GetApiClient(request.AccessToken);
         var envelopesApi = new EnvelopesApi(client);

         Envelope envelope = envelopesApi.GetEnvelope(_configuration["DocuSign:AccountId"], request.EnvelopId);
         EnvelopeFormData results = envelopesApi.GetFormData(_configuration["DocuSign:AccountId"], request.EnvelopId);

         if (envelope != null)
         {
             envelopeData = envelope;
         }
         //envelopeData.status show that document signed or not.
     }

     return await Task.FromResult(envelopeData);
 }

private async Task<ApiClient> GetApiClient(string token)
 {
     var docuSignConfig = new Configuration(_configuration["DocuSign:BaseURI"] + "/restapi");
     docuSignConfig.AddDefaultHeader("Authorization", "Bearer " + token);
     docuSignConfig.AccessToken = token;
     var apiClient = new ApiClient(docuSignConfig);
     apiClient.SetBasePath(docuSignConfig.BasePath);
     return await Task.FromResult(apiClient);
 }

Step 5:

Finally, add the GetDocumentData method in the DocuSignController.

[HttpPost("GetDocumentData")]
public async Task<IActionResult> GetDocumentData([FromBody] GetDocumentDataRequest request)
{
     var apiResponse = await _docuSignService.GetDocumentData(request);
     return new JsonResult(apiResponse);
}

Conclusion:

The document data will appear in the response when you complete this step. In the ‘status’ section, you’ll be able to check whether or not your document has been signed.

If status=completed, it implies that the user has reviewed and signed your document.

Related Articles:

Getting Started With The DocuSign

Get Authentication Token From The DocuSign (Part-1)

Get Authentication Token From The DocuSign (Part-2)

How To Create JSON Document File For Signature In DocuSign

Send Document To Other Users For Signature In DocuSign

Download Document From DocuSign

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories