Trending Topics: Latest from our forums (March 2023)

Here are some of the latest popular questions that the DocuSign developers community asked on Stack Overflow in the month of March 2023. You too can ask questions by using the tag docusignapi in Stack Overflow.

Thread: Why do all my DocuSign calls return "Invalid UserId."?

https://stackoverflow.com/questions/75678154/

Summary: The developer is using the DocuSign eSignature C# SDK and is getting an “Invalid UserId” error when trying to make API calls. They’re using JWT for authentication. 

Answer: When using JWT, you must make sure that the userId (GUID) that you provide in the process of obtaining an access token (that user will be impersonated by the API) is correct. That means that this user is a member of the same account that you will later use to make API calls, and that the accountId (GUID) is for the account for which this user is a member. Also, be careful to not confuse the developer and production accounts, which have separate account and user numbers. After you authenticate, you can obtain the account number for the authenticated user using the code below (note that this code assumes the user is a member of a single account; if they are a member of multiple accounts, you would have to choose the one you want):

string clientId = "**your-client-id**";
string userId = "**your-user-id**";
// demo site auth url: account-d.docusign.com
// prod site auth url: account.docusign.com
string oAuthBasePath = "account-d.docusign.com";                             
DocuSignClient authClient = new DocuSignClient();

var accessToken = authClient.RequestJWTUserToken(
     clientId,
     userId, 
     oAuthBasePath,
     System.IO.File.ReadAllBytes("privateKey.txt"),
     expiresInHours: 1,
     new List<string> { "signature", "impersonation" });

// Use received access token to get user info and account            
var userInfo = authClient.GetUserInfo(accessToken.access_token);
var account = userInfo.Accounts.FirstOrDefault();

Thread: DocuSign C# SDK No API Response

https://stackoverflow.com/questions/75688288/

Summary: This developer is also using the C# SDK and JWT and is unable to complete API calls successfully. This is the code they wrote:

var _apiClient = new DocuSignClient("https://demo.docusign.net/restapi");
var privateKeyBytes = GetPrivateKeyBytes();
var authToken = _apiClient.RequestJWTUserToken("integration_key", "user_id", "account-d.docusign.com", privateKeyBytes: privateKeyBytes, 1, new List<string> { "impersonation", "signature" });
// authToken object returns correctly with access_token, calling _apiClient.GetUserInfo(authToken.access_token) will return a valid object as well.
var envelopesAPI = new EnvelopesApi(_apiClient);
// never gets past this line, constantly loads.
Envelope env = envelopesAPI.GetEnvelope("api_account_id", "envelope_id");

Answer: The developer is missing the line that sets the HTTP header with the access token they received when they obtained it using the JWT authentication call. They need to add these two lines to their code:

string access_token = authToken.access_token;
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);

Thread: Creating templates by using generated URL

https://stackoverflow.com/questions/75665659/

Summary: The developer wants the end users of their application to be able to author DocuSign templates directly from their integration. They want the end users to be able to update documents and fields in the template, but not by doing it directly from the DocuSign web app.

Answer: Just as you can use embedded sending for envelopes, you can build an application that integrates the DocuSign functionality that enables users to compose a template. This process requires three steps in your integration:

  1. Create a new template
  2. Generate and embed the template author view in your application
  3. Create an envelope from the template and send it

Steps 1 and 3 above have detailed instructions and code examples in eight languages. Step 2 is similar to embedded signing, but requires a different endpoint to generate a template view. 

Additional resources

Inbar Gazit
Author
Inbar Gazit
Sr. Manager, Developer Content
Published