-->

Embedded Signing api docusign

2019-03-03 22:39发布

问题:

I'm using DocuSign to add eSignature to my requests and everything's working well. Right now I send my signature requests,by using Embedded method- to initiate my workflows immediately by navigating to a URL.

After login,and execute the bellow code,i get the (Embedded View: https://demo.docusign.net/Member/StartInSession.aspx?StartConsole=1&t=32598057-5a59-4d0b-bad8-a8ff8f2407f6&DocuEnvelope=168bc155-e013-4ffd-abb4-7608b56647f8&send=1), but whene i paste the url to try signing document in navigate, but will redirect me to an other url is(http://www.docusign.com/?event=Send&envelopeId=168bc155-e013-4ffd-abb4-7608b56647f8),

how can'i start wotkflow process to sign my enveloppe ?? i can't see my enveloppe to sign it.

// STEP 2 - Create an envelope with one recipient, document, and tab and send //

    String jsonBody = "{\"emailBlurb\":\"partail\"," + 
            "\"emailSubject\":\"API Call for adding signature request to document and sending\"," + 
            "\"documents\":[{" + 
            "\"documentId\":\"1\"," + 
            "\"name\":\"test.pdf\"}]," + 
            "\"recipients\":{" + 
            "\"signers\":[{" + 
            "\"email\":\"" + EmailRecipients + "\"," + 
            "\"name\":\"name\"," + 
            "\"recipientId\":\"1\"," +
            "\"routingOrder\":\"1\","+
            "\"clientUserId\":\"1000\","+              
            "\"tabs\":{" + 
            "\"signHereTabs\":[{" + 
            "\"xPosition\":\"300\"," + 
            "\"yPosition\":\"600\"," + 
            "\"documentId\":\"1\"," + 
            "\"pageNumber\":\"1\"" + "}]}}]}," + 
            "\"status\":\"sent\"}";
          //DemandeSign.getenvelope();


    File file = new File("D:/test.pdf");
    InputStream inputStream = new FileInputStream(file); 
    byte[] bytes = new byte[(int) file.length()];
    inputStream.read(bytes);
    inputStream.close();

    String requestBody = "\r\n\r\n--BOUNDARY\r\n" + 
            "Content-Type: application/json\r\n" + 
            "Content-Disposition: form-data\r\n" + 
            "\r\n" + 
            jsonBody + "\r\n\r\n--BOUNDARY\r\n" +   // our json formatted request body
            "Content-Type: application/pdf\r\n" + 
            "Content-Disposition: file; filename=\"test.pdf\"; 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";

    // append "/envelopes" to the baseUrl and use in the request
    conn = (HttpURLConnection)new URL(baseURL + "/envelopes").openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);
    conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
    conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=BOUNDARY");
    conn.setRequestProperty("Content-Length", Integer.toString(requestBody.toString().length()));
    conn.setRequestProperty("Accept", "application/xml"); 

    // 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();
    status = conn.getResponseCode(); // triggers the request
    if( status != 201 ) // 201 = Created
    {
        System.out.println("Error calling webservice, status is: " + status);
        InputStreamReader isr = new InputStreamReader( conn.getErrorStream() );
        br = new BufferedReader(isr);
        StringBuilder error_response = new StringBuilder();
        while ( (line = br.readLine()) != null)
            error_response.append(line);
        System.out.println("Error response is " + error_response.toString() );
        System.exit(-1);
    }
    // Read the response
    InputStreamReader isr = new InputStreamReader( conn.getInputStream() );
    br = new BufferedReader(isr);
    StringBuilder response2 = new StringBuilder();
    while ( (line = br.readLine()) != null)
        response2.append(line);
    //token1 = "//*[1]/*[local-name()='envelopeId']";
    //String envelopeId = xPath.evaluate(token1, new InputSource(new StringReader(response2.toString())));

    //--- display results
    //System.out.println("Document sent!  envelopeId is " + envelopeId );//envelopeId is e4c0659a-9d01-4ac3-a45f-02a80fd6bd96 at 04/07/2013 17:24


    token1 = "//*[1]/*[local-name()='uri']";
    String uri = xPath.evaluate(token1, new InputSource(new StringReader(response2.toString())));
    //--- display results
    System.out.println("uri = " + uri );


/// Step3
// construct another outgoing XML request body
String reqBody = "<returnUrlRequest xmlns=\"http://www.docusign.com/restapi\">" +
"<authenticationMethod>email</authenticationMethod>" +
"<email>***test@gmail.com***</email>" +
"<returnUrl>http://www.docusign.com</returnUrl>" +
"<userName>name</userName>" +
"<clientUserId>1000</clientUserId>" +
"</returnUrlRequest>";

// append uri + "/views/sender" to the baseUrl and use in the request
conn = (HttpURLConnection)new URL(baseURL + uri + "/views/sender").openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
conn.setRequestProperty("Content-Type", "application/xml");
conn.setRequestProperty("Content-Length", Integer.toString(reqBody.length()));
conn.setRequestProperty("Accept", "application/xml");
// write the body of the request...
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(reqBody); dos.flush(); dos.close();
status = conn.getResponseCode(); // triggers the request
if( status != 201 ) // 201 = Created
{
System.out.println("Error calling webservice, status is: " + status);
System.exit(-1);
}
// Read the response
isr = new InputStreamReader( conn.getInputStream() );
br = new BufferedReader(isr);
StringBuilder response3 = new StringBuilder();
while ( (line = br.readLine()) != null)
response3.append(line);
token1 = "//*[1]/*[local-name()='url']";
//--- display results
System.out.println("Embedded View: " + xPath.evaluate(token1, new InputSource(new StringReader(response3.toString()))));`

回答1:

Are you trying to access the URL immediately or are you waiting at all? Once you generate a URL token to access a given envelope it has a TTL (time to life) of 5 mins, meaning it expires after 5 minutes and you then need to generate a new one.

If that's not it, your problem might be related to how you are identifying your recipient. A recipient in DocuSign is identified by the unique combination of their name, email, recipientId, and in the case of embedding, the clientUserId. You seem to be setting all of those, however whatever the combination is when you first create the envelope, you need to refer to the same combination when you are requesting the Embedded URL token.

When you create your envelope I see you are setting the name literally to "name" and that you are setting the email through a variable called "EmailRecipients". But when you request the URL token you are using email "test@gmail.com", that might be causing your issue too.