Shawn
Shawn

Reputation: 11

DocuSign: Getting a list of all documents a user has access to

We are updating an application to allow users to upload/attach files directly from various external sources (DocuSign, Drop Box, Google Drive, etc). I am currently trying to get a list of all files a user has access to in their DocuSign account. I am working in C# with the DocuSign .NET REST API library (DocuSign.eSign.dll).

I can get as far as authenticating as the user and getting their default account id. I am trying to use the FoldersApi.Search method but I get a "404 - File or directory not found error". Can someone familiar with DocuSign review my code and tell me what I might be doing wrong?

var apiClient = new ApiClient("https://demo.docusign.net/restapi");

var code = Request["Code"];
var token = apiClient.GenerateAccessToken(IntegratorKey, SecretKey, code);

var userInfo = DocuSignClient.GetUserInfo(token.access_token);
var accountId = "";
foreach (var account in userInfo.Accounts) {
    if (account.IsDefault == "true") {
        accountId = account.AccountId;
        apiClient = new ApiClient(account.BaseUri);
        break;
    }
}

var configuration =
    new Configuration(apiClient: apiClient, accessToken: token.access_token);

var foldersApi = new FoldersApi(configuration);
var response = foldersApi.Search(accountId, "all");
foreach (var folder in response.FolderItems) {
    Context.Response.Write(folder.FolderId);
}

Upvotes: 0

Views: 680

Answers (2)

Ergin
Ergin

Reputation: 9356

I think I see an issue with your code though not in a good place to test currently, hopefully you can confirm soon. On the first line you correctly instantiate an API Client for demo environment with:

var apiClient = new ApiClient("https://demo.docusign.net/restapi");

However after authenticating and getting their user info, you then re-configure the base path with:

apiClient = new ApiClient(account.BaseUri);

I believe this might be leading to the 404 error because this will only contain the domain. In other words, this has the effect of doing:

apiClient = new ApiClient("https://demo.docusign.net");

You need to add the remaining /restapi/v2/{accountId} to form the proper base request URL, try something like this instead:

apiClient = new ApiClient(account.BaseUri + "/restapi/v2/accounts/" + accountId);

--------------------------------

UPDATE

Just did some testing and got things to work however note that I'm using Node.js not C#. Still should be same logic though. Here's my working code for getting all completed envelopes:

docusign.Configuration.default.setDefaultApiClient(apiClient);

var foldersApi = new docusign.FoldersApi(docusign.Configuration.default.getDefaultApiClient());
foldersApi.search(accountId, "completed")
    .then(function(response) { 
        console.log("response = " + JSON.stringify(response, null, 2));
        return null;
    })
    .catch(function (error){
    if (error) {
      console.log('Error: ' + JSON.stringify(error));
      return error;
    }
  });

Upvotes: 1

eitamal
eitamal

Reputation: 782

Caveat: I've never used DocuSign before. But having looked at the REST API and the .NET client I've come up with a possible solution.

It looks like you're using the folders search incorrectly. The signature for that API is as follows:

public FolderItemResponse Search (string accountId, string searchFolderId, FoldersApi.SearchOptions options = null)

Where the valid values for the searchFolderId are drafts, awaiting_my_signature, completed, or out_for_signature, but you've provided all which is the one of the search options not one of the search folder IDs.

The correct usage would be something like this:

var response = foldersApi.Search(accountId, "completed", FoldersApi.SearchOptions.all);

where you would replace completed with whatever value it is you need from the valid values I've mentioned above.

Upvotes: 1

Related Questions