使用模板获取UNKNOWN_ENVELOPE_RECIPIENT docusign php API

时间:2017-01-23 17:40:05

标签: php docusignapi

我正在研究Docusign php rest API。一切正常,但现在我必须使用这个模板。我为此编写了脚本。但现在我收到了这个错误。

  

错误代码:UNKNOWN_ENVELOPE_RECIPIENT错误消息:收件人   您已识别的不是指定的有效收件人   信封。

但是,如果我删除ClientUserId

$viewrequest->setClientUserId('12345');

我收到错误

  

错误代码:ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE错误消息:这   帐户无权访问所请求的信封。

这是我创建docusign请求的功能。

include_once('DocuSign/bootstrap.php');

echo signatureRequestFromTemplate();
function signatureRequestFromTemplate()
{
    $recipientEmail= "test@gmail.com";
    $recipientName = "test";
    $username = "testuser@gmail.com";
    $password = "telemate";
    $integrator_key = "SALE-252453454-54b3-4a86-bb25-1f21cb2edc21";
    $documentFileName = __DIR__ ."/Contract.pdf";
    $documentName = "datedDoc.txt";
    $host = "https://demo.docusign.net/restapi";

    // create configuration object and configure custom auth header
    $config = new DocuSign\eSign\Configuration();
    $config->setHost($host);
    $config->addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" . $username . "\",\"Password\":\"" . $password . "\",\"IntegratorKey\":\"" . $integrator_key . "\"}");

    // instantiate a new docusign api client
    $apiClient = new DocuSign\eSign\ApiClient($config);
    $accountId = null;

    try 
    {
        //*** STEP 1 - Login API: get first Account ID and baseURL
        $authenticationApi = new DocuSign\eSign\Api\AuthenticationApi($apiClient);
        $options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
        $loginInformation = $authenticationApi->login($options);
        if(isset($loginInformation) && count($loginInformation) > 0)
        {
            $loginAccount = $loginInformation->getLoginAccounts()[0];
            $host = $loginAccount->getBaseUrl();
            $host = explode("/v2",$host);
            $host = $host[0];

            // UPDATE configuration object
            $config->setHost($host);

            // instantiate a NEW docusign api client (that has the correct baseUrl/host)
            $apiClient = new DocuSign\eSign\ApiClient($config);

            if(isset($loginInformation))
            {
                $accountId = $loginAccount->getAccountId();
                if(!empty($accountId))
                {
                    //*** STEP 2 - Signature Request from a Template
                    // create envelope call is available in the EnvelopesApi
                    $envelopeApi = new DocuSign\eSign\Api\EnvelopesApi($apiClient);
                    // assign recipient to template role by setting name, email, and role name.  Note that the
                    // template role name must match the placeholder role name saved in your account template.
                    $templateRole = new  DocuSign\eSign\Model\TemplateRole();
                    $templateRole->setEmail($recipientEmail);
                    $templateRole->setName($recipientName);
                    $templateRole->setRoleName("Buyer");             

                    // instantiate a new envelope object and configure settings
                    $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
                    $envelop_definition->setEmailSubject("[DocuSign PHP SDK] - Signature Request Sample");
                    $envelop_definition->setTemplateId("EDAA30DE-551F-46C7-A7D3-9B6CA33AD07A");
                    $envelop_definition->setTemplateRoles(array($templateRole));

                    // set envelope status to "sent" to immediately send the signature request
                    $envelop_definition->setStatus("sent");

                    // optional envelope parameters
                    $options = new \DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions();
                    $options->setCdseMode(null);
                    $options->setMergeRolesOnDraft(null);

                    // create and send the envelope (aka signature request)
                    $envelop_summary = $envelopeApi->createEnvelope($accountId, $envelop_definition, $options);

                    $document=json_decode($envelop_summary);
                    $envloped=$document->envelopeId;

                    $ReturnUrl="http://www.test.com/demo2/?action=docusign_request&uid=10&envelopid=" . $envloped;
                    $viewrequest = new DocuSign\eSign\Model\RecipientViewRequest();
                    $viewrequest->setUserName($recipientName); 
                    $viewrequest->setEmail($recipientEmail);
                    //$viewrequest->setRecipientId(1);
                    //$viewrequest->setClientUserId('12345');
                    $viewrequest->setAuthenticationMethod('email');
                    $viewrequest->setReturnUrl($ReturnUrl);
                    $envelopview=$envelopeApi->createRecipientView($accountId,$document->envelopeId,$viewrequest);
                    echo $redirecturl=$envelopview->getUrl();
                    if(!empty($envelop_summary))
                    {
                        //echo "$envelop_summary";
                    }
                }
            }
        }
    }
    catch (DocuSign\eSign\ApiException $ex)
    {
        echo "Exception: " . $ex->getMessage() . "\n";
    }
}

我使用listRecipients对其进行测试,它给了我这个回复

DocuSign\eSign\Model\Recipients Object
(
    [signers:protected] => Array
        (
            [0] => DocuSign\eSign\Model\Signer Object
                (
                    [signature_info:protected] => 
                    [default_recipient:protected] => 
                    [tabs:protected] => 
                    [sign_in_each_location:protected] => false
                    [offline_attributes:protected] => 
                    [require_signer_certificate:protected] => 
                    [require_sign_on_paper:protected] => 
                    [can_sign_offline:protected] => 
                    [is_bulk_recipient:protected] => false
                    [bulk_recipients_uri:protected] => 
                    [recipient_supplies_tabs:protected] => 
                    [excluded_documents:protected] => 
                    [name:protected] => test
                    [email:protected] => test@gmail.com
                    [email_recipient_post_signing_url:protected] => 
                    [signing_group_id:protected] => 
                    [signing_group_name:protected] => 
                    [signing_group_users:protected] => 
                    [recipient_id:protected] => 1
                    [recipient_id_guid:protected] => e074bc90-44a0-4a0f-a9a6-68dd2ae3747c
                    [access_code:protected] => 
                    [add_access_code_to_email:protected] => 
                    [require_id_lookup:protected] => false
                    [id_check_configuration_name:protected] => 
                    [social_authentications:protected] => 
                    [phone_authentication:protected] => 
                    [saml_authentication:protected] => 
                    [sms_authentication:protected] => 
                    [user_id:protected] => a36eb466-1b84-47a4-9e0d-733d16637444
                    [client_user_id:protected] => 
                    [embedded_recipient_start_url:protected] => 
                    [custom_fields:protected] => 
                    [routing_order:protected] => 1
                    [id_check_information_input:protected] => 
                    [recipient_attachments:protected] => 
                    [note:protected] => 
                    [role_name:protected] => Buyer
                    [status:protected] => sent
                    [signed_date_time:protected] => 
                    [delivered_date_time:protected] => 
                    [declined_date_time:protected] => 
                    [sent_date_time:protected] => 
                    [declined_reason:protected] => 
                    [delivery_method:protected] => 
                    [fax_number:protected] => 
                    [template_locked:protected] => 
                    [template_required:protected] => 
                    [email_notification:protected] => 
                    [inherit_email_notification_configuration:protected] => 
                    [error_details:protected] => 
                    [recipient_authentication_status:protected] => 
                    [total_tab_count:protected] => 
                )

        )

    [agents:protected] => Array
        (
        )

    [editors:protected] => Array
        (
        )

    [intermediaries:protected] => Array
        (
        )

    [carbon_copies:protected] => Array
        (
        )

    [certified_deliveries:protected] => Array
        (
        )

    [in_person_signers:protected] => Array
        (
        )

    [recipient_count:protected] => 1
    [current_routing_order:protected] => 1
    [error_details:protected] => 
)

1 个答案:

答案 0 :(得分:1)

我已经解决了这个Errror。实际上我还需要在模板设置中添加ClientId。我刚刚添加了$templateRole->setClientUserId('12345');

$templateRole = new  DocuSign\eSign\Model\TemplateRole();
$templateRole->setEmail($recipientEmail);
$templateRole->setName($recipientName);
$templateRole->setRoleName("Buyer");             
$templateRole->setClientUserId('12345');  // added this