2017-01-23 62 views
0

我正在使用Docusign php rest API。一切正常,但現在我必須使用這個模板。我爲此寫了腳本。但現在我得到這個錯誤。使用模板獲取UNKNOWN_ENVELOPE_RECIPIENT docusign php API

錯誤代碼:UNKNOWN_ENVELOPE_RECIPIENT錯誤消息: 你已經確定收件人不是指定 信封的有效收件人。

但如果我刪除ClientUserId

$viewrequest->setClientUserId('12345'); 

我收到錯誤

錯誤代碼:ACCOUNT_NOT_AUTHORIZED_FOR_ENVELOPE錯誤信息:這 帳戶未授權訪問所請求的信封。

這是我創建docusign請求的函數。

include_once('DocuSign/bootstrap.php'); 

echo signatureRequestFromTemplate(); 
function signatureRequestFromTemplate() 
{ 
    $recipientEmail= "[email protected]"; 
    $recipientName = "test"; 
    $username = "[email protected]"; 
    $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] => [email protected] 
        [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] => 
) 
+0

請勿公開您的密碼和集成商密鑰。我建議你改變它們。 –

+0

這些不是實際值。 – MKD

+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