docusignapi - DocuSign "UNSPECIFIED_ERROR" Index was outside the bounds of the array -



docusignapi - DocuSign "UNSPECIFIED_ERROR" Index was outside the bounds of the array -

i'm trying create new envelope using docusign rest api version 2. response i'm getting:

{ "errorcode" : "unspecified_error", "message" : "index outside bounds of array." }

here's (sanitized , word wrapped) info that's beingness sent. note we're using oauth2.

post https://na2.docusign.net/restapi/v2/accounts/{account_id}/envelopes content-length: 72523 content-type: application/json accept: application/json authorization: bearer{oauth2_token} {"status": "created", "documents": [ {"documentbase64": "<deleted_base64_data>", "name": "sample document", "documentid": "1"} ], "emailsubject": "documents sign", "recipients": { "signers": [ {"recipientid": "1", "email": "user@example.com", "routingorder": "1", "name": "example user" } ] } }

any thoughts index out of bounds?

thanks

you have document bytes in wrong location, , need create proper multipart/form-data request create new docusign envelope. here total code sample in c#, re-create document same directory , fill in variables @ top , should work you.

note copied docusign api walkthroughs:

// docusign api walkthrough 04 in c# - request signature on document // // run sample: // 1) create new .net project. // 2) add together 4 assembly references project: system, system.net, system.xml, , system.xml.linq // 3) update email, password, integrator key, recipient name, , document name in code // 4) re-create sample pdf file project directory same name document name set in code // 5) compile , run // // note 1: docusign rest api accepts both json , xml formatted http requests. these c# api walkthroughs // demonstrate utilize of xml format, whereas other walkthroughs show examples in json format. using system; using system.io; using system.net; using system.xml; using system.xml.linq; namespace docusignapiwalkthrough04 { public class requestsignatureondocument { public static void main () { //--------------------------------------------------------------------------------------------------- // come in values next 6 variables: //--------------------------------------------------------------------------------------------------- string username = "***"; // business relationship email string password = "***"; // business relationship password string integratorkey = "***"; // business relationship integrator key (found on preferences -> api page) string recipientname = "***"; // recipient (signer) name string recipientemail = "***"; // recipient (signer) email string documentname = "***"; // re-create document same name , extension project directory (i.e. "test.pdf") string contenttype = "application/pdf"; // default content type pdf //--------------------------------------------------------------------------------------------------- // additional variable declarations string baseurl = ""; // - retrieve through login api phone call seek { //============================================================================ // step 1 - login api phone call (used retrieve baseurl) //============================================================================ // endpoint login api phone call (in demo environment): string url = "https://demo.docusign.net/restapi/v2/login_information"; // set request url, method, , headers. no body needed login api phone call httpwebrequest request = initializerequest( url, "get", null, username, password, integratorkey); // read http response string response = getresponsebody(request); // parse baseurl response body baseurl = parsedatafromresponse(response, "baseurl"); //--- display results console.writeline("\napi phone call result: \n\n" + prettyprintxml(response)); //============================================================================ // step 2 - send signature request template //============================================================================ /* docusign api phone call requires "multipart/form-data" content type. constructing request body in next format (each newline crlf): --aaa content-type: application/xml content-disposition: form-data <xml body goes here> --aaa content-type:application/pdf content-disposition: file; filename="document.pdf"; documentid=1 <document bytes go here> --aaa-- */ // append "/envelopes" baseurl , utilize signature request api phone call url = baseurl + "/envelopes"; // build outgoing xml formatted request body (json accepted) // .. next body adds 1 signer , places signature tab 100 pixels right // , 100 pixels downwards top left corner of document supply string xmlbody = "<envelopedefinition xmlns=\"http://www.docusign.com/restapi\">" + "<emailsubject>docusign api - signature request on document</emailsubject>" + "<status>sent</status>" + // "sent" send immediately, "created" save draft in business relationship // add together document(s) "<documents>" + "<document>" + "<documentid>1</documentid>" + "<name>" + documentname + "</name>" + "</document>" + "</documents>" + // add together recipient(s) "<recipients>" + "<signers>" + "<signer>" + "<recipientid>1</recipientid>" + "<email>" + recipientemail + "</email>" + "<name>" + recipientname + "</name>" + "<tabs>" + "<signheretabs>" + "<signhere>" + "<xposition>100</xposition>" + // default unit pixels "<yposition>100</yposition>" + // default unit pixels "<documentid>1</documentid>" + "<pagenumber>1</pagenumber>" + "</signhere>" + "</signheretabs>" + "</tabs>" + "</signer>" + "</signers>" + "</recipients>" + "</envelopedefinition>"; // set request url, method, headers. don't set body yet, we'll set separelty after // read document bytes , configure rest of multipart/form-data request request = initializerequest( url, "post", null, username, password, integratorkey); // config api phone call configuremultipartformdatarequest(request, xmlbody, documentname, contenttype); // read http response response = getresponsebody(request); //--- display results console.writeline("\napi phone call result: \n\n" + prettyprintxml(response)); } grab (webexception e) { using (webresponse response = e.response) { httpwebresponse httpresponse = (httpwebresponse)response; console.writeline("error code: {0}", httpresponse.statuscode); using (stream info = response.getresponsestream()) { string text = new streamreader(data).readtoend(); console.writeline(prettyprintxml(text)); } } } } // end main() //*********************************************************************************************** // --- helper functions --- //*********************************************************************************************** public static httpwebrequest initializerequest(string url, string method, string body, string email, string password, string intkey) { httpwebrequest request = (httpwebrequest)webrequest.create (url); request.method = method; addrequestheaders( request, email, password, intkey ); if( body != null ) addrequestbody(request, body); homecoming request; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static void addrequestheaders(httpwebrequest request, string email, string password, string intkey) { // authentication header can in json or xml format. xml used walkthrough: string authenticatestr = "<docusigncredentials>" + "<username>" + email + "</username>" + "<password>" + password + "</password>" + "<integratorkey>" + intkey + "</integratorkey>" + "</docusigncredentials>"; request.headers.add ("x-docusign-authentication", authenticatestr); request.accept = "application/xml"; request.contenttype = "application/xml"; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static void addrequestbody(httpwebrequest request, string requestbody) { // create byte array out of request body , add together request object byte[] body = system.text.encoding.utf8.getbytes (requestbody); stream datastream = request.getrequeststream (); datastream.write (body, 0, requestbody.length); datastream.close (); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static void configuremultipartformdatarequest(httpwebrequest request, string xmlbody, string docname, string contenttype) { // overwrite default content-type header , set boundary marker request.contenttype = "multipart/form-data; boundary=boundary"; // start building multipart request body string requestbodystart = "\r\n\r\n--boundary\r\n" + "content-type: application/xml\r\n" + "content-disposition: form-data\r\n" + "\r\n" + xmlbody + "\r\n\r\n--boundary\r\n" + // our xml formatted envelopedefinition "content-type: " + contenttype + "\r\n" + "content-disposition: file; filename=\"" + docname + "\"; documentid=1\r\n" + "\r\n"; string requestbodyend = "\r\n--boundary--\r\n\r\n"; // read contents of provided document request stream filestream filestream = file.openread(docname); // write body of request byte[] bodystart = system.text.encoding.utf8.getbytes(requestbodystart.tostring()); byte[] bodyend = system.text.encoding.utf8.getbytes(requestbodyend.tostring()); stream datastream = request.getrequeststream(); datastream.write(bodystart, 0, requestbodystart.tostring().length); // read file contents , write them request stream. read in blocks of 4096 bytes byte[] buf = new byte[4096]; int len; while ((len = filestream.read(buf, 0, 4096) ) > 0) { datastream.write(buf, 0, len); } datastream.write(bodyend, 0, requestbodyend.tostring().length); datastream.close(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static string getresponsebody(httpwebrequest request) { // read response stream local string httpwebresponse webresponse = (httpwebresponse)request.getresponse (); streamreader sr = new streamreader(webresponse.getresponsestream()); string responsetext = sr.readtoend(); homecoming responsetext; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static string parsedatafromresponse(string response, string searchtoken) { // "searchtoken" in response body , parse value using (xmlreader reader = xmlreader.create(new stringreader(response))) { while (reader.read()) { if((reader.nodetype == xmlnodetype.element) && (reader.name == searchtoken)) homecoming reader.readstring(); } } homecoming null; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// public static string prettyprintxml(string xml) { // print nicely formatted xml seek { xdocument doc = xdocument.parse(xml); homecoming doc.tostring(); } grab (exception) { homecoming xml; } } } // end class } // end namespace

docusignapi docusign

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -