0

Googleフォームが送信されるとDocusignで自動的に封筒を送信しようとしています。GoogleスプレッドシートとDocusign APIをGoogleスクリプトとリンクさせるにはどうすればよいですか?

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のスクリプトエディタで

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

を次のコードを書かれていますすばらしいです。

答えて

2

私はJSON形式でデータを送信していると指定していると思いますが、サーバーはおそらくそのデータを期待していますが、データはその形式ではありません。

デフォルトでは、提供中の​​オプションの引数としてJavaScriptオブジェクトが発生した場合、Apps Scriptをフォームデータとしてエンコードします。代わりに、指定の

は:これは役立つはず

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

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

あなたは指定する必要があります。

関連する問題