0
votes

Im fairly new to implementing the embedded signing using the rest api. I am able to start the signing session within the iframe but after finishing the document/template it is redirecting me to a url. Can anybody please let me know how or where do i configure the redirect url, i guess the url is appended with the status from where i can use this token within my app.

NeverMind.. i got it, can't believe i dint see that in the first place.

// STEP 3 - Get the Send View           

    String reqBody = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">"  +
            "<authenticationMethod>email</authenticationMethod>" + 
            "<email>[email protected]</email>" + 
            **"<returnUrl>http://www.docusign.com</returnUrl>" +** 
            "<clientUserId>1</clientUserId>" + 
            "<userName>" + recipientName + "</userName>" + 
            "</recipientViewRequest>";
1

1 Answers

1
votes

Looks like you answered your own question but for the benefit of the community, one of the DocuSign API recipes demonstrates all the steps for Embedded Signing.

Here is the full PHP version of the code. As you've found out, you can set the URL where users get redirected to after signing by setting the returnUrl property in your request body.

Here's the full PHP program for Embedded Signing. You can also find this here

<?php

    // Input your info:
    $integratorKey = '...';
    $email = '[email protected]';
    $password = '...';
    $name = "John Doe";

    // copy the templateId of an existing template here
    $templateId = "C9D9D181-CE57-.....................";

    // construct the authentication header:
    $header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // STEP 1 - Login (retrieves baseUrl and accountId)
    /////////////////////////////////////////////////////////////////////////////////////////////////
    $url = "https://demo.docusign.net/restapi/v2/login_information";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));

    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    if ( $status != 200 ) {
        echo "error calling webservice, status is:" . $status;
        exit(-1);
    }

    $response = json_decode($json_response, true);
    $accountId = $response["loginAccounts"][0]["accountId"];
    $baseUrl = $response["loginAccounts"][0]["baseUrl"];
    curl_close($curl);

    //--- display results
    echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n";

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
    /////////////////////////////////////////////////////////////////////////////////////////////////
    $data = array("accountId" => $accountId, 
        "emailSubject" => "Hello World!",
        "emailBlurb" => "This comes from PHP",
        "templateId" => $templateId, 
        "templateRoles" => array(
            array( "email" => $email, "name" => $name, "roleName" => "Signer1", "clientUserId" => "1001" )),
        "status" => "sent");                                                                    

    $data_string = json_encode($data);  
    $curl = curl_init($baseUrl . "/envelopes" );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string),
        "X-DocuSign-Authentication: $header" )                                                                       
    );

    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 201 ) {
        echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
        print_r($json_response); echo "\n";
        exit(-1);
    }

    $response = json_decode($json_response, true);
    $envelopeId = $response["envelopeId"];
    curl_close($curl);

    //--- display results   
    echo "Envelope created! Envelope ID: " . $envelopeId . "\n"; 

    /////////////////////////////////////////////////////////////////////////////////////////////////
    // STEP 3 - Get the Embedded Singing View 
    /////////////////////////////////////////////////////////////////////////////////////////////////
    $data = array("returnUrl" => "http://www.docusign.com/devcenter",
        "authenticationMethod" => "None", "email" => $email, 
        "userName" => $name, clientUserId => "1001"
    );                                                                    

    $data_string = json_encode($data);    
    $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string),
        "X-DocuSign-Authentication: $header" )                                                                       
    );

    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 201 ) {
        echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
        print_r($json_response); echo "\n";
        exit(-1);
    }

    $response = json_decode($json_response, true);
    $url = $response["url"];

    //--- display results
    echo "Embedded URL is: \n\n" . $url . "\n\nNavigate to this URL to start the embedded signing view of the envelope\n"; 
?>