Google apps script 如何将Google Sheets和Docusign API与Google脚本链接?
我试图在提交谷歌表单时自动发送一个带有Docusign的信封。我在Google脚本编辑器中编写了以下代码Google apps script 如何将Google Sheets和Docusign API与Google脚本链接?,google-apps-script,docusignapi,google-spreadsheet-api,Google Apps Script,Docusignapi,Google Spreadsheet Api,我试图在提交谷歌表单时自动发送一个带有Docusign的信封。我在Google脚本编辑器中编写了以下代码 // 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
// 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);
}
//表单提交时
函数onFormSubmit(e){
//从表单中获取信息并设置变量
var full_name=e.values[2];
var email_address=e.values[3];
//发送电子邮件
var subject=“测试触发器”;
var body=“感谢您的测试”+全名+”;
MailApp.sendEmail(电子邮件地址,
主题,,
身体);
变量url=”https://demo.docusign.net/restApi/v2/accounts//envelopes";
var有效载荷=
{
“emailSubject”:“请在邮件上签名”,
“emailBlurb”:“TestTextTestText”,
“模板ID”:“7078020e-49a0-42c6-b77d-368211d4a666”,
“模板材料”:[
{
“roleName”:“客户”,
“姓名”:全名,
“电子邮件”:电子邮件地址
},
{
“roleName”:“名称”,
“名称”:“名称”,
“电子邮件”:“电子邮件地址”
},
{
“roleName”:“名称2”,
“名称”:“名称2”,
“电子邮件”:“电子邮件地址2”
}
],
“状态”:“已发送”
}
var期权=
{
“contentType”:“application/json”,
“方法”:“发布”,
“标题”:
{
“X-DocuSign-Authentication:“{\”用户名\“:\”、\”密码\“:\”、\”集成密钥\“:\”}”
},
“有效载荷”:有效载荷
};
fetchapp.fetch(url,选项);
}
我收到以下错误消息,似乎格式有问题:
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."
}
POSThttps://demo.docusign.net:7802/restApi/v2/accounts//envelopes
TraceToken:0304eb5f-1188-4880-a22c-861839f4e8d9
时间戳:2016-10-25T09:40:49.0423980Z
内容长度:187
内容类型:application/json
连接:保持活力
主机:demo.docusign.net
用户代理:Mozilla/5.0(兼容;谷歌应用程序脚本)
X-DocuSign-Authentication:{“用户名”:“,“密码”:“[省略]”,“积分器密钥”:“[省略]”}
X-BROKER-EVENT-ID:AHI413WWv-VgeLRQbOpMQH-Y6J-93aHL4h5phAVpXeXUqK8RsYof90Eu68CI-LkC1Ef4FM8Hac-1
X-For:107.178.192.41
X-SecurityProtocol-Version:TLSv1.2
X-SecurityProtocol-CipherSuite:ECDHE-RSA-AES256-GCM-SHA384
接受:application/json
emailBlurb=testTextTestText&templateRoles=%5BLjava.lang.Object@3449f174&templateId=7078020e-49a0-42c6-b77d-368211d4a666&emailSubject=Please+sign+stuff&status=sent
400坏请求
内容类型:application/json;字符集=utf-8
{
“错误代码”:“无效的请求\u正文”,
“消息”:“请求正文丢失或格式不正确。分析值时遇到意外字符:e.路径“”,第0行,位置0。”
}
任何关于如何进行的帮助都将是巨大的 我认为问题在于,您指定提交的是JSON格式的数据,而服务器可能希望这样做,但事实上,您的数据不是JSON格式的 默认情况下,当遇到一个JavaScript对象作为
payload
选项的参数时,正如您提供的那样,应用程序脚本将其编码为表单数据
而不是指定:
// 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)
这应该会有所帮助。我认为问题在于,您指定提交的数据是JSON格式的,服务器可能希望这样做,但事实上您的数据不是JSON格式的 默认情况下,当遇到一个JavaScript对象作为
payload
选项的参数时,正如您提供的那样,应用程序脚本将其编码为表单数据
而不是指定:
// 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)
这应该会有所帮助