docusignapi - How to link Google Sheets and Docusign API with Google Scripts? -


i trying automatically send envelope docusign when google form submitted. have written following code in google script editor

// when form gets submitted  function onformsubmit(e) {  //get information form , set our variables     var full_name = e.values[2];   var email_address = e.values[3];  // send email    var subject = "test trigger";   var body    = "thank 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 following error message , seems there wrong 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 missing or improperly formatted. unexpected character encountered while parsing value: e. path '', line 0, position 0." } 

any on how proceed great.

i think problem you're specifying submitting data in json format, , server presumably expecting in fact data not in format.

by default, when encountering javascript object argument payload option, providing, apps script encode form data.

instead of specifying:

// payload js object , encoded formdata default "payload" : payload 

you need specify:

// payload json representation of payload variable. "payload" : json.stringify(payload) 

this should help.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -