I have a concept tester C# solution working for Docusign.Click - Embed Elastic Signing Agreement. Including retrieving agreement response data by Agreement-Id and Agreements-Info by Client-Id. We are in the situation that in a later month. We may need to send the same elastic signing agreement to the same client-id, for re-signing.
How does one do this?
Can it be done without deleting the prior agreements for this client-id, and without creating a new elastic template?
So far in my testing I have arguments sent into the elastic signing template for client: name, email, company, and date. A change of date has not tripped a new agreement but I get an already agreed response. I checked the response output in debug, and no new agreement-url was generated.
Thanks.
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;
using DocuSign.eSign.Model;
using static DocuSign.Click.Api.AccountsApi;
namespace DocuSignConsoleTester
{
internal class Program
{
public static void Main(string[] args)
{
string integrationKey = "xx..xx";
string userId = "xx..xx";
string accountId = "xx..xx";
string authServer = "account-d.docusign.com"; // for demo environment
string accountBaseURI = "https://demo.docusign.net/clickapi"; // for demo environment
string fullName = "xx..xx";
string email = "xyz@example.com";
string company = "xx..xx";
string title = "xx..xx";
string clickwrapId = "xx..xx";
string datenow = DateTime.Now.ToString();
string access_token = GetJwtToken(integrationKey, userId, accountId, authServer);
Console.WriteLine("Acess_Token: [" + access_token + "]");
Console.WriteLine("\r\r");
AccountsApi clickAccountApi = BuildHeader(accountBaseURI, access_token);
UserAgreementRequest userAgreementRequest = BuildUpdateClickwrapHasAgreedRequest(fullName, email, company, title, datenow);
ApiResponse<UserAgreementResponse> apiAgreement = CreateAgreement(clickAccountApi, accountId, clickwrapId, userAgreementRequest);
string AgreedOn = apiAgreement.Data.AgreedOn.ToString();
string agreementId = apiAgreement.Data.AgreementId;
string agreementURL = apiAgreement.Data.AgreementUrl;
string clientUserid = apiAgreement.Data.ClientUserId;
string createdOn = apiAgreement.Data.CreatedOn.ToString();
UserAgreementResponse AgreementInfo = GetAgreementInfo(clickAccountApi, accountId, clickwrapId, agreementId);
List<UserAgreementResponse> ClientAgreementList = GetClientAgreementInfo(clickAccountApi, accountId, clickwrapId, agreementId, clientUserid);
Console.WriteLine("API response data: ");
Console.WriteLine(apiAgreement.Data.ToString());
Console.WriteLine("\r\r");
Console.WriteLine("Agreement response data: ");
Console.WriteLine(AgreementInfo.ToString());
Console.WriteLine("\r\r");
Console.WriteLine("Client agreement data: ");
foreach (UserAgreementResponse a in ClientAgreementList)
{
Console.WriteLine(a.ToString());
Console.WriteLine("\r");
}
Console.WriteLine("\r\r");
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 impersonation click.manage click.send" };
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 dsClient = new DocuSignClient(basePath);
dsClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var clickAccountApi = new AccountsApi(dsClient);
return clickAccountApi;
}
public static UserAgreementRequest BuildUpdateClickwrapHasAgreedRequest(string fullName, string email, string company, string title, string 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);
userAgreementRequest.ClientUserId = email;
return userAgreementRequest;
}
public static ApiResponse<UserAgreementResponse> CreateAgreement(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;
}
}
public static UserAgreementResponse GetAgreementInfo(AccountsApi clickAccountApi, string accountId, string clickwrapId, string agreementId)
{
UserAgreementResponse response = clickAccountApi.GetAgreement(accountId, clickwrapId, agreementId);
return response;
}
public static List<UserAgreementResponse> GetClientAgreementInfo(AccountsApi clickAccountApi, string accountId, string clickwrapId,
string agreementId, string clientId)
{
GetClickwrapAgreementsOptions gcao = new GetClickwrapAgreementsOptions();
gcao.clientUserId = clientId;
ClickwrapAgreementsResponse acctResponse = clickAccountApi.GetClickwrapAgreements(accountId, clickwrapId, gcao);
List<UserAgreementResponse> usrAgreements = acctResponse.UserAgreements.ToList();
return usrAgreements;
}
}
}