【问题标题】:How to use information from Google Forms/Docs in Docusign and vice versa?如何在 Docusign 中使用来自 Google 表单/文档的信息,反之亦然?
【发布时间】:2016-10-19 15:09:55
【问题描述】:

我想使用 Google 表单中的信息(在提交时)使用 Docusign api 从模板发送信封。

信封完成后,我想向同一个人发送不同的 Google Form 和 Google Doc。另外,我想在步骤完成后发送一些电子邮件。

我研究过使用适用于表单、文档和电子邮件的 Google Apps 脚本,但我不知道如何从那里运行 Docusign api。任何帮助是极大的赞赏。

更新:根据您的帮助,我提出了以下建议。当我运行下面的代码时,我收到一条错误消息:“未找到或禁用指定的积分器密钥。未指定积分器密钥。”。集成器密钥处于活动状态,但它可能与重定向 URI 或密钥有关吗?我没有设置它们。

// When Form Gets submitted

function onFormSubmit(e) {

//Get information from form and set our variables 

  var full_name = e.values[2];
  var email_address = e.values[3];

// Send the email

  var subject = "TEST trigger";
  var body    = "Thank you for testing" + full_name + "";

  MailApp.sendEmail(email_address, 
                    subject, 
                    body); 

// SEND DOCUSIGN ENVELOPE FROM TEMPLATE

   var url = "https://demo.docusign.net/restApi/v2/accounts/<accountid>/envelopes";

   var payload =
   {
  "emailSubject": "Please sign stuff",
  "emailBlurb": "TesttextTesttextTesttextTesttextTesttext",
  "templateId": "<templateID>",
  "templateRoles": [
    {
      "roleName": "role1",
      "name": full_name,
      "email": email_address
    },
    {
      "roleName": "role2",
      "name": "John Doe",
      "email": "JohnDoe@email.com"
    },
    {
      "roleName": "role3",
      "name": "Joe Smith",
      "email": "joesmith@email.com"
    }
  ],
  "status": "sent"
   }

   var options =
   {
     "method" : "post",
     "header": 
     {
    "X-DocuSign-Authentication": "{\"Username\":\<username>\",\"Password\":\"<passwork>\",\"IntegratorKey\":\"<integratorkey>\"}"
  },
     "payload" : payload
   };

   UrlFetchApp.fetch(url, options);
 }

更新:我将header 更改为headers,但现在我得到了一个不同的错误。 Ergin,正如你所说,我记录了请求。下面是错误信息。内容类型似乎有问题。

POST https://demo.docusign.net:7802/restApi/v2/accounts/<accountID>/envelopes

TraceToken: <token>
Timestamp: 2016-10-24T07:24:27.6912557Z

Content-Length: 187
Content-Type: application/x-www-form-urlencoded
Connection: Keep-alive
Host: demo.docusign.net
User-Agent: Mozilla/5.0(compatible; Google-Apps-Script)
X-DocuSign-Authentication: {"Username":"<my email address>","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-BROKER-EVENT-ID: AHI413UAlYti8n93Pw-ZxoDmQoiCcwanMroRR1LDTgseOKFBkZVomEVZwdxJ-kajUMDC4NN__Z7e
X-Forwarded-For: 107.178.203.22
X-SecurityProtocol-Version: TLSv1.2
X-SecurityProtocol-CipherSuite: ECDHE-RSA-AES256-GCM-SHA384

emailBlurb=TesttextTesttextTesttextTesttextTesttext&templateRoles=%5BLjava.lang.Object;@17be0aa5&templateId=7078020e-49a0-42c6-b77d-368211d4a666&emailSubject=Please+sign+stuff&status=sent
415 UnsupportedMediaType
Content-Type: application/json; charset=utf-8

{
  "errorCode": "INVALID_CONTENT_TYPE",
  "message": "Content Type specified is not supported."
}

更新:设置内容类型后,我收到正文格式不正确的错误。见下文

POST https://demo.docusign.net:7802/restApi/v2/accounts/<accountid>/envelopes

TraceToken: 0304eb5f-1188-4880-a22c-861839f4e8d9
Timestamp: 2016-10-25T09:40:49.0423980Z

Content-Length: 187
Content-Type: application/json
Connection: Keep-alive
Host: demo.docusign.net
User-Agent: Mozilla/5.0(compatible; Google-Apps-Script)
X-DocuSign-Authentication: {"Username":"<email>","Password":"[omitted]","IntegratorKey":"[omitted]"}
X-BROKER-EVENT-ID: AHI413WWv-VgeLRQbOpMQH-Y6J-93aHL4h5phAVpXeXUqK8RsYof90Eu68CI-LkC1Ef4FM8Hac-1
X-Forwarded-For: 107.178.192.41
X-SecurityProtocol-Version: TLSv1.2
X-SecurityProtocol-CipherSuite: ECDHE-RSA-AES256-GCM-SHA384
Accept: application/json

emailBlurb=TesttextTesttextTesttextTesttextTesttext&templateRoles=%5BLjava.lang.Object;@3449f174&templateId=7078020e-49a0-42c6-b77d-368211d4a666&emailSubject=Please+sign+stuff&status=sent
400 BadRequest
Content-Type: application/json; charset=utf-8

{
  "errorCode": "INVALID_REQUEST_BODY",
  "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: e. Path '', line 0, position 0."
}

【问题讨论】:

    标签: google-apps-script docusignapi google-docs-api google-sheets-api


    【解决方案1】:

    您的请求当然会根据一些因素而有所不同,例如有多少收件人和选项卡(字段),但在基本级别上,要从模板发送签名请求,您需要向信封 URI 发出 http POST 请求,并使用请求正文中的模板信息:

    POST https://demo.docusign.net/restApi/v2/accounts/{accountId}/envelopes
    
    {
        "status": "sent",
        "emailSubject": "Request a signature via email example",
        "templateId": "44D9E888-3D86-4186-8EE9-7071BC87A0DA",
        "templateRoles": [
            {
                "email": "sally.doe@email.com",
                "name": "John Dough",
                "roleName": "RoleOne",
                "tabs": {
                    "textTabs": [
                        {
                            "tabLabel": "ApplicantName",
                            "value": "John Dough"
                        },
                        {
                            "tabLabel": "ApplicantSSN",
                            "value": "12-345-6789"
                        }
                    ]
                }
            }
        ]
    }
    

    您可以测试信封:通过DocuSign API Explorer 创建API。

    【讨论】:

    • 谢谢埃尔金。我可以通过我的 Google 应用脚本执行此操作吗?
    • 嗨@Ergin,我刚刚发布了更新。你能看看吗?
    • 错误消息告诉您它在请求中找不到您的集成密钥,假设您传递有效密钥,我会检查并确保您的身份验证标头正确附加。我看到你添加了一个header 节点来添加标题,通常应该是复数headers。尝试更改为,如果这不起作用,那么您应该在您的帐户中启用请求登录并运行跟踪,以便您可以检查传入的请求。
    • 感谢 Ergin,第一个障碍是 header 而不是 headers。不幸的是,我现在收到另一个错误,说内容类型有问题。请参阅上面的更新。这可能与有效载荷的格式有关吗?
    • 尝试添加content-type 标头并将其设置为application/json。如果这不起作用,如前所述,请跟踪您的请求,然后在您的问题中发布原始请求。
    【解决方案2】:

    您可以使用Class ItemResponse 获取对表单中一个问题项的回复。可以从FormResponse 访问项目响应,并从要求受访者回答问题的任何项目创建。

    这里是一个示例代码sn-p:

    // Open a form by ID and log the responses to each question.
    var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
    var formResponses = form.getResponses();
    for (var i = 0; i < formResponses.length; i++) {
      var formResponse = formResponses[i];
      var itemResponses = formResponse.getItemResponses();
       for (var j = 0; j < itemResponses.length; j++) {
         var itemResponse = itemResponses[j];
         Logger.log('Response #%s to the question "%s" was "%s"',
             (i + 1).toString(),
             itemResponse.getItem().getTitle(),
             itemResponse.getResponse());
       }
    }
    

    ...但我不知道如何从那里运行 Docusign api。

    您可以查看此documentation,因为 Google Apps 脚本可以与来自整个网络的 API 进行交互。如果您想使用不能用作 Apps 脚本服务的 Google 或非 Google API,您可以通过 URL Fetch service 连接到 API 的公共 HTTP 接口。

    此服务允许脚本通过获取 URL 来访问网络上的其他资源。脚本可以使用 UrlFetch 服务发出 HTTP 和 HTTPS 请求并接收响应。 UrlFetch 服务使用 Google 的网络基础架构来提高效率和扩展规模。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      • 2017-09-14
      相关资源
      最近更新 更多