如何将Google表格和Docusign

如何将Google表格和Docusign

本文介绍了如何将Google表格和Docusign API与Google脚本链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在提交Google表单时自动发送带有Docusign的信封。我已经在Google脚本编辑器中编写了以下代码

I am trying to automatically send an envelope with Docusign when a Google form is submitted. I have written the following code in the Google Script Editor

// 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);

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

   var payload =
   {
  "emailSubject": "Please sign stuff",
  "emailBlurb": "TesttextTesttextTesttextTesttextTesttext",
  "templateId": "7078020e-49a0-42c6-b77d-368211d4a666",
   "templateRoles": [
    {
      "roleName": "client",
      "name": full_name,
      "email": email_address
    },
    {
      "roleName": "name",
      "name": "name",
      "email": "emailaddress"
    },
    {
      "roleName": "name2",
      "name": "name2",
      "email": "emailaddress2"
    }
  ],
  "status": "sent"
   }

   var options =
   {
     "contentType": "application/json",
     "method" : "post",
     "headers":
     {
    "X-DocuSign-Authentication": "{\"Username\":\"<username>\",\"Password\":\"<pw>\",\"IntegratorKey\":\"<integratorkey>"}"
  },
     "payload" : payload
   };

   UrlFetchApp.fetch(url, options);
 }

我收到以下错误消息,看来格式化存在问题:

I get the following error message and it seems there is something wrong with the formatting:

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."
}

任何有关执行方法的帮助都将非常有用。

Any help on how to proceed would be great.

推荐答案

我认为问题在于您指定的是以JSON格式提交数据,并且服务器可能正在等待

I think the problem is that you're specifying that you are submitting data in JSON format, and the server is presumably expecting that but in fact your data is not in that format.

默认情况下,当遇到JavaScript对象作为 payload 选项(如您所提供),带有将其编码为表单数据的Apps脚本。

By default, when encountering a JavaScript object as an argument to the payload option, as you are providing, Apps Script with encode it as a form data.

而不是指定:

// Payload is a JS object and will be encoded as formdata by default
"payload" : payload

您需要指定:

// Payload is now a JSON representation of the payload variable.
"payload" : JSON.stringify(payload)

这应该有所帮助。

这篇关于如何将Google表格和Docusign API与Google脚本链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:41