我在使用以下代碼在我的開發人員帳戶中工作時遇到問題。我不斷收到以下錯誤:Docusign API transformPdfFields&php
「ERROR calling webservice,status is:400 error text is - > {」errorCode「:」ENVELOPE_IS_INCOMPLETE「,」message「:」The Envelope is not Complete。完整的信封需要文檔,收件人,選項卡和主題行。「}」
任何人都有一個想法,爲什麼會出現此錯誤?該「檢驗.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";
謝謝。我正在嘗試這個配方。我在文件中擁有憑證(用戶名,密碼,api密鑰),但它沒有任何地方可以清楚地定義文件名和路徑。我應該在那裏添加別的東西嗎?我是否必須對pdf進行編碼並將字節剪切/粘貼到該php文件中? – Brent
$ documentFileName應該是您的文件的路徑+名稱 - 如果它與您的腳本位於同一目錄中,它應該只是'test.pdf'IMO。 file_get_contents PHP函數應該完成拉取PDF字節的工作 - 配方的其餘部分將把這些字節放入API調用的有效負載中 –