You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用C#库向DocuSign模板填充数据遇到问题求助

C#实现通过Data Label更新DocuSign模板文本框值的示例

我来帮你搞定用C# DocuSign SDK通过Data Label填充模板文本框的需求,结合你提供的代码和请求响应来看,核心逻辑已经走通了,下面给你梳理下完整的实现要点和注意事项:

完整实现代码示例

using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using System.Collections.Generic;
using System.Threading.Tasks;

public async Task<string> CreateEnvelopeWithTemplateData(string accountId, string templateId)
{
    // 初始化DocuSign客户端(需提前完成认证配置)
    var envelopesApi = new EnvelopesApi();

    // 1. 创建模板角色,对应模板中设置的收件人
    TemplateRole signer1 = new TemplateRole();
    signer1.Name = "John Doe";
    signer1.Email = "BOB@AOL.COM";
    signer1.RoleName = "Owner"; // 必须与模板内的收件人角色名称完全匹配

    // 2. 创建文本标签,关联模板中的Data Label
    Text text1 = new Text();
    text1.TabLabel = "FullName"; // 必须与模板文本框的Data Label完全一致(大小写敏感)
    text1.Value = "EP"; // 要填充到文本框的实际内容

    // 3. 将文本标签绑定到对应收件人角色
    signer1.Tabs = new Tabs();
    signer1.Tabs.TextTabs = new List<Text>();
    signer1.Tabs.TextTabs.Add(text1);

    // 4. 构建信封定义
    EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
    envelopeDefinition.TemplateId = templateId;
    envelopeDefinition.Status = "created"; // 若需直接发送给收件人,改为"sent"
    envelopeDefinition.EmailSubject = "eSign";

    // 5. 将模板角色添加到信封中
    List<TemplateRole> templateroles = new List<TemplateRole>() { signer1 };
    envelopeDefinition.TemplateRoles = templateroles;

    // 6. 调用API创建信封
    EnvelopeSummary envelopeSummary = await envelopesApi.CreateEnvelopeAsync(accountId, envelopeDefinition);
    return envelopeSummary.EnvelopeId;
}

关键注意事项

  • Data Label与TabLabel严格匹配:从你提供的Data Label截图可知,文本框的Data Label为FullName,代码中text1.TabLabel必须和这个值完全一致(包括大小写)——DocuSign对TabLabel的匹配是大小写敏感的,拼写或大小写错误会导致填充失败。
  • 模板角色名称精准对应:你的Recipient截图显示模板内的收件人角色是Owner,代码里signer1.RoleName必须和该角色名完全匹配,否则文本标签无法关联到正确的收件人。
  • 信封状态按需设置:你当前设置的status: "created"会生成草稿信封,保存在DocuSign账户中;如果需要直接发送给收件人,只需将状态改为"sent"即可。
  • 从你的请求响应来看:信封已经成功创建(返回201 Created和有效envelopeId),如果模板文本框仍未被填充,优先检查Data Label和角色名的匹配问题。

请求与响应详情

请求JSON

POST https://demo.docusign.net:7801/restapi/v2/accounts/4794997/envelopes
TraceToken: fe59bc72-61f3-4c07-9eeb-0d53d558437a
Timestamp: 2018-05-21T18:36:48.4260253Z
Content-Length: 255
Content-Type: application/json
Connection: Keep-Alive
Accept: application/json
Host: demo.docusign.net
X-DocuSign-SDK: C#
X-DocuSign-Authentication: {"Username":"[omitted]", "Password":"[omitted]", "IntegratorKey":"[omitted]"}
x-ms-request-root-id: dba2cd44-40b5e3581ae1a62d
x-ms-request-id: |dba2cd44-40b5e3581ae1a62d.2.
Request-Id: |dba2cd44-40b5e3581ae1a62d.2.
X-SecurityProtocol-Version: TLSv1.2
X-SecurityProtocol-CipherSuite: ECDHE-RSA-AES256-GCM-SHA384
x-forwarded-for: 24.1.74.183

{"emailSubject":"eSign With Payment From API","status":"created","templateId":"bd417d79-2a0b-4d76-8970-e2d18451c2f5","templateRoles":[{"email":"BOB@AOL.COM","name":"John Doe","roleName":"Owner","tabs":{"textTabs":[{"tabLabel":"FullName","value":"EP"}]}}]}

响应JSON

201 Created
Content-Type: application/json; charset=utf-8
X-DocuSign-TraceToken: fe59bc72-61f3-4c07-9eeb-0d53d558437a

{
 "envelopeId": "13fb444c-79cc-43bb-b6d4-3a6241c84ebc",
 "uri": "/envelopes/13fb444c-79cc-43bb-b6d4-3a6241c84ebc",
 "statusDateTime": "2018-05-21T18:36:46.9570000Z",
 "status": "created"
}

内容的提问来源于stack exchange,提问作者Eric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:41:29