2016-08-23 3 views
0

У меня возникли проблемы с получением нижеприведенного кода для работы в моей учетной записи разработчика. Я продолжаю получать следующую ошибку:Docusign API transformPdfFields & php

«ERROR вызывает веб-сервис, статус: 400 текст ошибки -> {« errorCode »:« ENVELOPE_IS_INCOMPLETE »,« message »:« Конверт не завершен. Полный конверт требует документов, получателей, вкладок и темы. "}"

У кого-нибудь есть идея, почему эта ошибка возникает? «Test.pdf» находится в том же каталоге, что и файл docusign.php, который код ниже:

///////////////////////////////////////////////////////////////////////////////////////////////// 

    // STEP 2 - Establish Credentials & Variables 

    ///////////////////////////////////////////////////////////////////////////////////////////////// 

    // Input your info here: 

    $name = "John P. Doe"; //The user from Docusign (will show on the email as the sender of the contract) 

    $email = " MY EMAIL ACCOUT USED FOR DOCUSIGN "; 

    $password = " MY PASSWORD FOR DOCUSIGN "; // The password for the above user 

    $integratorKey = " MY API KEY FOR DEMO "; 





    // construct the authentication header: 

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



    ///////////////////////////////////////////////////////////////////////////////////////////////// 

    // STEP 3 - Login (to retrieve 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:<BR>"; 

     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 "\naccountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n"; 

    echo "Document is being prepared. Please stand by.<br>Do not navigate away from this page until sending is confirmed.<br><br>"; 



    ///////////////////////////////////////////////////////////////////////////////////////////////// 

    // STEP 4 - Create an envelope using composite templates 

    /////////////////////////////////////////////////////////////////////////////////////////////////                 





    $data_string = 

    " 

     { 

      \"status\":\"sent\", 

      \"emailSubject\":\"Test transforming pdf forms and assigning them to each user\", 

      \"emailBlurb\":\"Test transforming pdf forms and assigning them to each user\", 

      \"compositeTemplates\":[ 

       { 

        \"inlineTemplates\":[ 

         { 

         \"sequence\": \"1\", 

         \"recipients\":{ 

          \"signers\":[ 

           { 

            \"email\":\"[email protected]\", 

            \"name\":\"Signer One\", 

            \"recipientId\":\"1\", 

            \"routingOrder\":\"1\", 

            \"tabs\":{ 

            \"textTabs\":[ 

             { 

              \"tabLabel\":\"PrimarySigner\", 

              \"value\":\"Signer One\" 

             } 

            ] 

            } 

           }, 

           { 

            \"email\":\"[email protected]\", 

            \"name\":\"Signer Two\", 

            \"recipientId\":\"2\", 

            \"routingOrder\":\"2\", 

            \"tabs\":{ 

            \"textTabs\":[ 

             { 

              \"tabLabel\":\"SecondarySigner\", 

              \"value\":\"Secondary One\" 

             } 

            ] 

            } 

           } 

          ] 

         } 

         } 

        ], 

        \"document\": { 

         \"documentId\": \"1\", 

         \"name\": \"test.pdf\", 

         \"transformPdfFields\": \"true\" 

        } 

       } 

      ] 

      } 

     "; 



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



    // --- display results 

    echo "Document is sent!<br> Envelope: " . $envelopeId . "\n\n"; 

ответ

0

Из того, что я могу сказать, фактический PDF байт test.pdf не передаются в часть этого запроса API, поэтому сообщение об ошибке вызывает тот факт, что вы ссылаетесь на отсутствующий документ. Посмотрите на примеры PHP рецепт для того, как вы можете прочитать PDF байт из файла и включить его в запросе API:

https://www.docusign.com/developer-center/recipes/request-a-signature-via-email

В частности, эта строка и переменная: $ file_contents = file_get_contents ($ documentFileName);

+0

спасибо. Я сейчас пробую этот рецепт. У меня есть мои учетные данные (пользователь, пароль, ключ api) в файле, но у меня нет нигде, где я вижу четкое определение имени файла и пути. Должен ли я добавить что-то еще там? И нужно ли мне кодировать PDF-файл и вырезать/вставить байты в этот файл php? – Brent

+0

$ documentFileName должен быть пустым + именем вашего файла - если его в том же каталоге, что и ваш скрипт, он должен быть просто «test.pdf» IMO. Функция file_get_contents PHP должна выполнять работу по извлечению байтов PDF - остальная часть рецепта поместит байты в полезную нагрузку вызова API –

Смежные вопросы