Docusign API transformPdfFields& PHP

时间:2016-08-23 14:58:10

标签: php docusignapi

我在使用以下代码在我的开发者帐户中工作时遇到问题。我一直收到以下错误:

" ERROR调用webservice,状态为: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"; 

1 个答案:

答案 0 :(得分:0)

据我所知,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);