如何使用Docusign中Google Forms / Docs的信息,反之亦然?

时间:2016-10-19 15:09:56

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

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

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

我看过使用适用于表单,文档和电子邮件的Google Apps脚本,但我无法弄清楚如何从那里运行Docusign api。任何帮助是极大的赞赏。

更新:根据您的帮助,我提出了以下建议。当我运行下面的代码时,我得到一个错误:"未找到或禁用指定的Integrator Key。未指定Integrator密钥。"。积分器密钥是活动的,但是它可能与重定向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."
}

2 个答案:

答案 0 :(得分: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。

答案 1 :(得分:0)

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

以下是一个示例代码段:

// 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来访问Web上的其他资源。脚本可以使用UrlFetch服务发出HTTP和HTTPS请求并接收响应。 UrlFetch服务使用Google的网络基础架构来实现效率和扩展。

希望这有帮助!