简体   繁体   English

Docusign REST API获取文档信封的收件人URL

[英]Docusign REST API Getting recipient URL for document envelope

I have a web app that takes a user through a series of forms and then generates a pdf with their answers. 我有一个网络应用程序,可以引导用户完成一系列表格,然后生成包含其答案的pdf文件。 I want to add a Docusign signature to the end of the pdf form, so that after finishing the online form they are asked to sign it in an iframe. 我想在pdf表格的末尾添加Docusign签名,以便在完成在线表格后要求他们在iframe中对其进行签名。

I started with this doc - https://www.docusign.com/developer-center/recipes/signing-from-your-app and then took step 2 from this doc to create my envelope with a document - https://www.docusign.com/developer-center/recipes/request-a-signature-via-email 我从此文档开始-https: //www.docusign.com/developer-center/recipes/signing-from-your-app ,然后从该文档开始执行步骤2,以创建包含文档的信封-https:// www .docusign.com / developer-center / recipes / request-a-signature-via-email

My code created the Envelope ID fine, but when I try to get the URL using /envelopes/$envelopeId/views/recipient I get the status 400 error: 我的代码很好地创建了信封ID,但是当我尝试使用/envelopes/$envelopeId/views/recipient获取URL时,状态为400错误:

{ "errorCode": "ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE", "message": "This account is not authorized to access the requested envelope." }

Here is my full code below: 这是我的完整代码如下:

<?php

$docusign_username = "my@username.com";
$docusign_password = "mypassword";
$docusign_integrator_key = "my-integrator-key";

$applicant_email = "johnsmith@emailaddress.com";
$applicant_name = "John Smith";
$applicant_unique_id = "123";

$application_unique_id = "31587";
$application_form_pdf = "31587.pdf";

// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $docusign_username . "</Username><Password>" . $docusign_password . "</Password><IntegratorKey>" . $docusign_integrator_key . "</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 document
//////////////////////////////////////////////////////////////////////////////////////
$data =
    array (
        "emailSubject" => "DocuSign API - Please sign " . $application_form_pdf,
        "documents" => array(
            array("documentId" => $application_unique_id, "name" => $application_form_pdf)
            ),
        "recipients" => array(
            "signers" => array(
                array(
                    "email" => $applicant_email,
                    "name" => $applicant_name,
                    "clientUserId" => $applicant_unique_id,
                    "recipientId" => $applicant_unique_id,
                    "tabs" => array(
                        "signHereTabs" => array(
                            array(
                                "xPosition" => "100",
                                "yPosition" => "100",
                                "documentId" => $application_unique_id,
                                "pageNumber" => "1"
                            )
                        )
                    )
                )
            )
        )
    , "status" => "sent"
    // , "status" => "created"
);
$data_string = json_encode($data);
$file_contents = file_get_contents($application_form_pdf);

// Create a multi-part request. First the form data, then the file content
$requestBody =
     "\r\n"
    ."\r\n"
    ."--myboundary\r\n"
    ."Content-Type: application/json\r\n"
    ."Content-Disposition: form-data\r\n"
    ."\r\n"
    ."$data_string\r\n"
    ."--myboundary\r\n"
    ."Content-Type:application/pdf\r\n"
    ."Content-Disposition: file; filename=\"$application_form_pdf\"; documentid=".$application_unique_id." \r\n"
    ."\r\n"
    ."$file_contents\r\n"
    ."--myboundary--\r\n"
    ."\r\n";

// Send to the /envelopes end point, which is relative to the baseUrl received above.
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: multipart/form-data;boundary=myboundary',
    'Content-Length: ' . strlen($requestBody),
    "X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl); // Do it!

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

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

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

//////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Signing View
//////////////////////////////////////////////////////////////////////////////////////
$data = array(
      "returnUrl" => "https://www.docusign.com/devcenter"
    , "authenticationMethod" => "None"
    , "authenticationInstant" => "None"
    , "userId" => $applicant_unique_id
    , "clientUserId" => $applicant_unique_id
    // , "email" => $applicant_email
    // , "userName" => $applicant_name
);

$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";

?>

Any ideas would be gratefully received, thanks! 任何想法将不胜感激,谢谢!

When obtaining the recipient view (the signing view), try identifying the signer by just specifying the 在获取收件人视图(签名视图)时,尝试通过仅指定

"email" => $email, # signer's email
"userName" => $recipientName,
"clientUserId" => $clientUserId

as shown in the embedded signing recipe. 如嵌入式签名食谱中所示。

Don't set the userId 不要设置userId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM