DocuSign API 模板与无模板电子邮件回复
DocuSign API Template vs. no Template email response
我正在开发一个在 iframe 中使用 DocuSign 签名的应用程序,该应用程序位于专有网络应用程序中。签名者能够在同一个网络应用程序中访问嵌入式 iframe 签名视图。
它是在没有考虑模板的情况下开发的。我已经通过构建包含 templateKey 和相应的 TemplateRoles 的 envelopeDefinition 实现了模板的使用。为非模板和模板信封调用相同的“CreateEnvelope”函数,但参数不同。 “设置”页面加载了已选择的模板、已定义的角色和已设置的字段。单击“发送”按钮时出现问题。
没有模板,就不会向签名者发送电子邮件。它允许签名者以嵌入式形式在我正在使用的专有应用程序中这样做。这是用于创建没有模板的信封的函数:
public EnvelopeSummary CreateEnvelope(string filePath, string username = null, string emailSubject = null, string brandID = null,List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID
};
if (recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
envelopeDef.Recipients = new Recipients() { Signers = signers };
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID, envelopeDefinition: envelopeDef, options: null);
}
应用模板后,在工作流通过 return URL 的 SenderView returned 到专有应用程序之前,签名者会收到一封电子邮件以获取外部签名。以下是用于使用模板创建信封的代码:
public EnvelopeSummary CreateTemplateEnvelope(string filePath,
List<DataModels.GetRole> roles = null,
DataModels.GetTemplate template = null,
string username = null,
string emailSubject = null,
string brandID = null,
List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID,
TemplateId = template.TemplateKey
};
if (roles != null && recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
var templateRoles = new List<TemplateRole>();
int counter = 0;
foreach (Signer signr in signers)
{
TemplateRole thisSigner = new TemplateRole();
thisSigner.Email = signers[counter].Email;
thisSigner.Name = signers[counter].Name;
thisSigner.RoleName = roles[counter].RoleName;
templateRoles.Add(thisSigner);
counter++;
}
envelopeDef.TemplateRoles = templateRoles;
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID,
envelopeDefinition: envelopeDef,
options: null);
}
主要区别在于模板版本包含 templateKey,并且它使用 TemplateRoles 而不是 Recipients。模板代码比我想要的最终产品要粗糙一些,但这是一项正在进行的工作,只是试图获得它 运行。有没有人知道如何或是否可以创建信封然后保留使用嵌入式签名的能力?感谢您的帮助。
编辑:已解决
如答案评论中所述,通过根据接收者的值正确设置每个模板角色的 ClientUserId 解决了该问题。这允许使用模板角色签名者进行嵌入式签名。
要使用模板,您必须先从模板创建一个信封。
模板本身无法发送,因此您不能对模板 per-se 使用嵌入式签名,只能使用它创建的信封。
这里是 code example in seven languages. It shows the first part, to get embedded signing from the resulted envelope you can use this code example.
这是为您准备的 C# 代码:
string DoWork (string signerEmail, string signerName, string ccEmail,
string ccName, string accessToken, string basePath,
string accountId, string templateId)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
// accessToken
// basePath
// accountId
// templateId
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, templateId);
EnvelopeSummary result = envelopesApi.CreateEnvelope(accountId, envelope);
return result.EnvelopeId;
}
private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
{
// Data for this method
// signerEmail
// signerName
// dsPingUrl -- class global
// signerClientId -- class global
// dsReturnUrl -- class global
RecipientViewRequest viewRequest = new RecipientViewRequest();
// Set the url where you want the recipient to go once they are done signing
// should typically be a callback route somewhere in your app.
// The query parameter is included as an example of how
// to save/recover state information during the redirect to
// the DocuSign signing ceremony. It's usually better to use
// the session mechanism of your web framework. Query parameters
// can be changed/spoofed very easily.
viewRequest.ReturnUrl = dsReturnUrl + "?state=123";
// How has your app authenticated the user? In addition to your app's
// authentication, you can include authenticate steps from DocuSign.
// Eg, SMS authentication
viewRequest.AuthenticationMethod = "none";
// Recipient information must match embedded recipient info
// we used to create the envelope.
viewRequest.Email = signerEmail;
viewRequest.UserName = signerName;
viewRequest.ClientUserId = signerClientId;
// DocuSign recommends that you redirect to DocuSign for the
// Signing Ceremony. There are multiple ways to save state.
// To maintain your application's session, use the pingUrl
// parameter. It causes the DocuSign Signing Ceremony web page
// (not the DocuSign server) to send pings via AJAX to your
// app,
viewRequest.PingFrequency = "600"; // seconds
// NOTE: The pings will only be sent if the pingUrl is an https address
viewRequest.PingUrl = dsPingUrl; // optional setting
r
eturn viewRequest;
}
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName,
string ccEmail, string ccName, string templateId)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
// templateId
EnvelopeDefinition env = new EnvelopeDefinition();
env.TemplateId = templateId;
TemplateRole signer1 = new TemplateRole();
signer1.Email = signerEmail;
signer1.Name = signerName;
signer1.RoleName = "signer";
singer1.ClientUserId = "001";
TemplateRole cc1 = new TemplateRole();
cc1.Email = ccEmail;
cc1.Name = ccName;
cc1.RoleName = "cc";
env.TemplateRoles = new List<TemplateRole> { signer1, cc1 };
env.Status = "sent";
return env;
}
我正在开发一个在 iframe 中使用 DocuSign 签名的应用程序,该应用程序位于专有网络应用程序中。签名者能够在同一个网络应用程序中访问嵌入式 iframe 签名视图。
它是在没有考虑模板的情况下开发的。我已经通过构建包含 templateKey 和相应的 TemplateRoles 的 envelopeDefinition 实现了模板的使用。为非模板和模板信封调用相同的“CreateEnvelope”函数,但参数不同。 “设置”页面加载了已选择的模板、已定义的角色和已设置的字段。单击“发送”按钮时出现问题。
没有模板,就不会向签名者发送电子邮件。它允许签名者以嵌入式形式在我正在使用的专有应用程序中这样做。这是用于创建没有模板的信封的函数:
public EnvelopeSummary CreateEnvelope(string filePath, string username = null, string emailSubject = null, string brandID = null,List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID
};
if (recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
envelopeDef.Recipients = new Recipients() { Signers = signers };
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID, envelopeDefinition: envelopeDef, options: null);
}
应用模板后,在工作流通过 return URL 的 SenderView returned 到专有应用程序之前,签名者会收到一封电子邮件以获取外部签名。以下是用于使用模板创建信封的代码:
public EnvelopeSummary CreateTemplateEnvelope(string filePath,
List<DataModels.GetRole> roles = null,
DataModels.GetTemplate template = null,
string username = null,
string emailSubject = null,
string brandID = null,
List<Models.Recipient> recipients = null)
{
EnvelopeDefinition envelopeDef = new EnvelopeDefinition
{
Status = "created",
EmailSubject = emailSubject,
BrandId = brandID,
TemplateId = template.TemplateKey
};
if (roles != null && recipients != null)
{
List<Signer> signers = recipients.Select(x => new Signer() { Email = x.Email, Name = x.UserName, ClientUserId = x.RecipientID > 50 ? x.RecipientID.ToString() : null, RecipientId = x.RouteOrder.ToString(), RoutingOrder = x.RouteOrder.ToString() }).ToList();
var templateRoles = new List<TemplateRole>();
int counter = 0;
foreach (Signer signr in signers)
{
TemplateRole thisSigner = new TemplateRole();
thisSigner.Email = signers[counter].Email;
thisSigner.Name = signers[counter].Name;
thisSigner.RoleName = roles[counter].RoleName;
templateRoles.Add(thisSigner);
counter++;
}
envelopeDef.TemplateRoles = templateRoles;
}
return Factory.GetEnvelopesApi(DocuSignConfig).CreateEnvelope(accountId: Helpers.SettingsHelper.AccountID,
envelopeDefinition: envelopeDef,
options: null);
}
主要区别在于模板版本包含 templateKey,并且它使用 TemplateRoles 而不是 Recipients。模板代码比我想要的最终产品要粗糙一些,但这是一项正在进行的工作,只是试图获得它 运行。有没有人知道如何或是否可以创建信封然后保留使用嵌入式签名的能力?感谢您的帮助。
编辑:已解决
如答案评论中所述,通过根据接收者的值正确设置每个模板角色的 ClientUserId 解决了该问题。这允许使用模板角色签名者进行嵌入式签名。
要使用模板,您必须先从模板创建一个信封。 模板本身无法发送,因此您不能对模板 per-se 使用嵌入式签名,只能使用它创建的信封。 这里是 code example in seven languages. It shows the first part, to get embedded signing from the resulted envelope you can use this code example.
这是为您准备的 C# 代码:
string DoWork (string signerEmail, string signerName, string ccEmail,
string ccName, string accessToken, string basePath,
string accountId, string templateId)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
// accessToken
// basePath
// accountId
// templateId
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName, ccEmail, ccName, templateId);
EnvelopeSummary result = envelopesApi.CreateEnvelope(accountId, envelope);
return result.EnvelopeId;
}
private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
{
// Data for this method
// signerEmail
// signerName
// dsPingUrl -- class global
// signerClientId -- class global
// dsReturnUrl -- class global
RecipientViewRequest viewRequest = new RecipientViewRequest();
// Set the url where you want the recipient to go once they are done signing
// should typically be a callback route somewhere in your app.
// The query parameter is included as an example of how
// to save/recover state information during the redirect to
// the DocuSign signing ceremony. It's usually better to use
// the session mechanism of your web framework. Query parameters
// can be changed/spoofed very easily.
viewRequest.ReturnUrl = dsReturnUrl + "?state=123";
// How has your app authenticated the user? In addition to your app's
// authentication, you can include authenticate steps from DocuSign.
// Eg, SMS authentication
viewRequest.AuthenticationMethod = "none";
// Recipient information must match embedded recipient info
// we used to create the envelope.
viewRequest.Email = signerEmail;
viewRequest.UserName = signerName;
viewRequest.ClientUserId = signerClientId;
// DocuSign recommends that you redirect to DocuSign for the
// Signing Ceremony. There are multiple ways to save state.
// To maintain your application's session, use the pingUrl
// parameter. It causes the DocuSign Signing Ceremony web page
// (not the DocuSign server) to send pings via AJAX to your
// app,
viewRequest.PingFrequency = "600"; // seconds
// NOTE: The pings will only be sent if the pingUrl is an https address
viewRequest.PingUrl = dsPingUrl; // optional setting
r
eturn viewRequest;
}
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName,
string ccEmail, string ccName, string templateId)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
// templateId
EnvelopeDefinition env = new EnvelopeDefinition();
env.TemplateId = templateId;
TemplateRole signer1 = new TemplateRole();
signer1.Email = signerEmail;
signer1.Name = signerName;
signer1.RoleName = "signer";
singer1.ClientUserId = "001";
TemplateRole cc1 = new TemplateRole();
cc1.Email = ccEmail;
cc1.Name = ccName;
cc1.RoleName = "cc";
env.TemplateRoles = new List<TemplateRole> { signer1, cc1 };
env.Status = "sent";
return env;
}