Thank you for your assistance.
I’m an experienced programmer working with C# for about 5 years. Currently I am getting deeper into API work. The current project is a console proof of concept test solution for an API call to DocuSign’s embed an elastic template functionality. I have a DocuSign developer account with an application, integration, and elastic template setup for use with the below. Ids, secrets, keys, etc., and the impersonation permission grant was successfully done.
I have followed the examples in DocuSign’s developer support information on their website and in GitHub. I have double/triple checked what I coded against the examples. I do not see where this error is coming from or how to resolve it.
I checked the other occurrences of this error, but none seemed to use the newer DocuSign.Click NuGet packages.
What am I missing here?
SETUP
The error occurs in-- “CallClickAPI(clickAccountApi, accountId, clickwrapId, userAgreementRequest)”
When this line is executed— “ApiResponse<UserAgreementResponse> response = clickAccountApi.CreateHasAgreedWithHttpInfo( accountId, clickwrapId, userAgreementRequest);”
TEST RUN NARRATIVE
DocuSign.Click.Client.ApiException HResult=0x80131500 Message=Unexpected character encountered while parsing value: <. Path '', line 0, position 0. Source=DocuSign.Click StackTrace: at DocuSign.Click.Client.DocuSignClient.Deserialize(DocuSignResponse response, Type type) at DocuSign.Click.Api.AccountsApi.<CreateHasAgreedAsyncWithHttpInfo>d__25.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at DocuSign.Click.Api.AccountsApi.CreateHasAgreedWithHttpInfo(String accountId, String clickwrapId, UserAgreementRequest userAgreementRequest) at DocuSignConsoleTester.Program.CallClickAPI(AccountsApi clickAccountApi, String accountId, String clickwrapId, UserAgreementRequest userAgreementRequest) in C:\T\repos\DocuSignConsoleTester\DocuSignConsoleTester\Program.cs:line 87 at DocuSignConsoleTester.Program.Main(String[] args) in C:\T\repos\DocuSignConsoleTester\DocuSignConsoleTester\Program.cs:line 37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuSign.Click.Api;
using DocuSign.Click.Client;
using DocuSign.Click.Model;
using DocuSign.Click.Client.Auth;
namespace DocuSignConsoleTester
{
internal class Program
{
static void Main(string[] args)
{
string clientId = "xx...xx";
string userId = "xx...xx";
string accountId = "xx...xx";
string authServer = "account-d.docusign.com"; // for demo environment
string base_path = "https://account-d.docusign.com/"; // for demo environment
string fullName = "xyz";
string email = "xyz@gmail.com";
string company = "xyz at Universe End";
string title = "xyuz Proprietor ";
string clickwrapId = "xx...xx";
DateTime date = DateTime.Now;
string access_token = GetJwtToken(clientId, userId, accountId, authServer);
Console.WriteLine("Acess_Token: [" + access_token + "]");
AccountsApi clickAccountApi = BuildHeader(base_path, access_token);
UserAgreementRequest userAgreementRequest = BuildUpdateClickwrapHasAgreedRequest( fullName, email, company, title, date);
ApiResponse<UserAgreementResponse> response = CallClickAPI(clickAccountApi, accountId, clickwrapId, userAgreementRequest);
Console.WriteLine(" End of test run ");
}
public static string GetJwtToken(string clientId, string userId, string accountId, string authServer)
{
string oauthBasePath = authServer;
int expiresInHours = 1;
//List<string> scopes = new List<string>() { "signature" };
//List<string> scopes = new List<string>() { "impersonation" };
List<string> scopes = new List<string>() { "signature impersonation" };
DocuSignClient dsClient = new DocuSignClient(authServer);
string rsaKeyBase64 = @"xx...xx==";
var rsaKeyBytes = Convert.FromBase64String(rsaKeyBase64);
OAuth.OAuthToken token = dsClient.RequestJWTUserToken(clientId, userId, oauthBasePath, rsaKeyBytes, expiresInHours, scopes);
return token.access_token.ToString();
}
public static AccountsApi BuildHeader(string basePath, string accessToken)
{
var apiClient = new DocuSignClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var clickAccountApi = new AccountsApi(apiClient);
return clickAccountApi;
}
public static UserAgreementRequest BuildUpdateClickwrapHasAgreedRequest(string fullName, string email, string company, string title, DateTime date)
{
var userAgreementRequest = new UserAgreementRequest { DocumentData = new Dictionary<string, string>() };
userAgreementRequest.DocumentData.Add("fullName", fullName);
userAgreementRequest.DocumentData.Add("email", email);
userAgreementRequest.DocumentData.Add("company", company);
userAgreementRequest.DocumentData.Add("title", title);
userAgreementRequest.DocumentData.Add("date", date.ToString());
userAgreementRequest.ClientUserId = email;
return userAgreementRequest;
}
public static ApiResponse<UserAgreementResponse> CallClickAPI(AccountsApi clickAccountApi, string accountId, string clickwrapId, UserAgreementRequest userAgreementRequest)
{
ApiResponse<UserAgreementResponse> response = clickAccountApi.CreateHasAgreedWithHttpInfo(accountId, clickwrapId, userAgreementRequest);
if (response.StatusCode == 201)
{
//return response.Data;
return response;
}
else
{
response.Data.AgreementUrl = "Already Agreed";
return response;
}
}
}
}
I did the above debug run. I was expecting it to return the response information; which would contain the embed URL amongst other information.
The issue is your base_path
string base_path = "https://account-d.docusign.com/"
This is wrong, should be instead
string base_path = "https://demo.docusign.net/clickapi"