簡體   English   中英

Docusign API transformPdfFields和PHP

[英]Docusign API transformPdfFields & php

我在使以下代碼在我的開發人員帳戶中正常工作時遇到問題。 我不斷收到以下錯誤:

“錯誤,正在調用Web服務,狀態是: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\":\"test1@test.com\",

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

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

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

                                  \"tabs\":{

                                     \"textTabs\":[

                                        {

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

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

                                        }

                                     ]

                                  }

                               },

                               {

                                  \"email\":\"test2@test.com\",

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

據我所知,test.pdf的實際PDF字節不是作為此API請求的一部分發送的-因此,錯誤消息表明您正在引用缺少的文檔。 查看PHP食譜示例,了解如何從文件讀取PDF字節並將其包含在API請求中:

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

具體來說,以下行和變量:$ file_contents = file_get_contents($ documentFileName);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM