0
votes

I am using the REST API in Java for DocuSign. I'm trying to embed signing (ultimately into an iframe in my page) with a document, instead of a template like in the API walkthroughs. Looking through here, I read that this could be accomplished by just merging code from the embeddedSigning and requestSigning API walkthroughs but I've had a hard time doing that. Now I think I'm close but stuck on an error where I have no idea what it's talking about.

    //============================================================================
    //STEP 2 - Signature Request on Document API Call
    //============================================================================
    url = baseURL + "/envelopes";   // append "/envelopes" to baseUrl for signature request call
    //this example uses XML formatted requests, JSON format is also accepted
    //following body will place one signature tab 100 pixels right and 100 down from top left corner of document
    body = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
        "<status>sent</status>" +
        "<emailSubject>API Call for adding signature request to document and sending</emailSubject>" +
        //add document(s)
        "<documents>" +
            "<document>" +
                "<documentId>1</documentId>" +
                "<name>" + documentName + "</name>" +
            "</document>" +
        "</documents>" +
        //add recipient(s)
        "<recipients>" +
            "<signers>" +
                "<signer>" +
                    "<recipientId>1</recipientId>" +
                    "<name>" + recipientName + "</name>" +
                    "<email>" + recipientEmail + "</email>" +   
                    "<clientUserId>1001</clientUserId>" +
                    "<tabs>" +
                        "<signHereTabs>" +
                            "<signHere>" +
                                "<xPosition>100</xPosition>" +
                                "<yPosition>100</yPosition>" +
                                "<documentId>1</documentId>" +
                                "<pageNumber>1</pageNumber>" +
                            "</signHere>" +
                        "</signHereTabs>" +
                    "</tabs>" +
                "</signer>" +
            "</signers>" +
        "</recipients>" +
        "</envelopeDefinition>";
    // re-use connection object for second request...
            conn = InitializeRequest(url, "POST", body, authenticationHeader);

            // read document content into byte array
            File file = new File("./" + documentName);
            InputStream inputStream = new FileInputStream(file); 
            byte[] bytes = new byte[(int) file.length()];
            inputStream.read(bytes);
            inputStream.close();

            // start constructing the multipart/form-data request...
            String requestBody = "\r\n\r\n--BOUNDARY\r\n" + 
                    "Content-Type: application/xml\r\n" + 
                    "Content-Disposition: form-data\r\n" + 
                    "\r\n" + 
                    body + "\r\n\r\n--BOUNDARY\r\n" +   // our xml formatted request body
                    "Content-Type: " + docContentType + "\r\n" + 
                    "Content-Disposition: file; filename=\"" + documentName + "\"; documentid=1\r\n" + 
                    "\r\n";
                // we break this up into two string since the PDF doc bytes go here and are not in string format.
                // see further below where we write to the outputstream...
            String reqBody2 = "\r\n" + "--BOUNDARY--\r\n\r\n";

            // write the body of the request...
            DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
            dos.writeBytes(requestBody.toString()); 
            dos.write(bytes);
            dos.writeBytes(reqBody2.toString()); 
            dos.flush(); dos.close();

            System.out.println("STEP 2: Creating envelope from document...\n");

            status = conn.getResponseCode(); // triggers the request
            if( status != 201 ) // 201 = Created
            {
                errorParse(conn, status);
                return;
            }

            // obtain envelope uri from response body 
            response = getResponseBody(conn);
            String uri = parseXMLBody(response, "uri");
            System.out.println("-- Envelope Creation response --\n\n" + prettyFormat(response, 2));
    //============================================================================
            //STEP 3 - Get the Embedded Signing View
            //============================================================================
            url = baseURL + uri + "/views/recipient";   // append envelope uri + "views/recipient" to url
            //this example uses XML formatted requests, JSON format is also accepted
            body = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
                "<authenticationMethod>email</authenticationMethod>" +
                "<email>" + recipientEmail + "</email>" +
                "<returnUrl>http://www.docusign.com/devcenter</returnUrl>" +
                "<clientUserId>1001</clientUserId>" +   //*** must match clientUserId set in Step 2!
                "<userName>" + recipientName + "</userName>" +
            "</recipientViewRequest>";
            System.out.print("Step 3: Generating URL token for embedded signing... ");
            conn = InitializeRequest(url, "POST", body, authenticationHeader);
            status = conn.getResponseCode(); // triggers the request
            if( status != 201 ) // 201 = Created
            {
                errorParse(conn, status);
                return;
            }
            System.out.println("done.");

            response = getResponseBody(conn);
            String urlToken = parseXMLBody(response, "url");
            System.out.println("\nEmbedded signing token created:\n\t" + urlToken);

And I get this error:

Step 3: Generating URL token for embedded signing... API call failed, status returned was: 411[Fatal Error] :1:50: White spaces are required between publicId and systemId.

I'm new to all this so any help with exactly how I was supposed to be embedding signing with documents would be greatly appreciated. ERROR: 'White spaces are required between publicId and systemId.'

1
I've never seen that error, can you post what is being passed (a trace) and a full error. It doesn't sound like it's coming from DocuSign - Andrew

1 Answers

1
votes

According to the RFC 2616 standards HTTP error 411 represents a missing Content-Length header. Try adding the Content-Length header to the request and set it to the size of the request body you are constructing.