根据REST API中的示例,是否有人成功将文档添加到草稿信封中?
https://demo.docusign.net/Member/noname.pdf?d=00000000-0000-0000-0000-000000000000&...
我用于#2的PUT请求:
X-DocuSign-Authentication:{“SendOnBehalfOf”:“xxx”,“Username”:“xxx”,“Password”:“xxx”,“IntegratorKey”:“xxx”} 接受:application / json 内容类型:application / pdf 内容处理:文件;文件名= “api_upload.pdf”; documentId = 3; fileExtension = “PDF” Content-Transfer-Encoding:base64
[删除了base64编码的字节]
任何建议都将受到赞赏。
答案 0 :(得分:0)
我刚刚测试过并且能够使用以下PHP代码将两个文档添加到草稿信封中。如果您输入凭证,此代码将登录,创建草稿信封,然后将两个文档添加到该草稿信封中,一次性完成。
仅运行此代码:
注意:此调用的REST API文档存在一些不准确之处,下面的请求正文可以正常工作,因此请按照此说明进行操作...
<?php
// Input your info here:
$integratorKey = '...';
$email = '...';
$password = '...';
$name = 'John Doe';
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - 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 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";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create a draft envelope
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array (
"emailBlurb" => "This comes from PHP",
"emailSubject" => "DocuSign API Testing",
"status" => "created");
$data_string = json_encode($data);
// *** append "/envelopes" to baseUrl and as signature request endpoint
$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',
"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";
return;
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Document is created! Envelope ID = " . $envelopeId . "\n\n";
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Add documents to draft envelope
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array (
"documents" => array(
array( "documentId" => "1", "name" => "document1.pdf", "order" => "1" ),
array( "documentId" => "2", "name" => "document2.pdf", "order" => "2" )
));
$data_string = json_encode($data);
$file_contents1 = file_get_contents("document1.pdf");
$file_contents2 = file_get_contents("document2.pdf");
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data_string\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"document1.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents1\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"document2.pdf\"; documentid=2 \r\n"
."\r\n"
."$file_contents2\r\n"
."--myboundary--\r\n"
."\r\n";
// *** append "/envelopes/{envelopeId}/documents" to baseUrl and as endpoint
$url = $baseUrl . "/envelopes/$envelopeId/documents";
$curl = curl_init( $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data;boundary=myboundary',
'Content-Length: ' . strlen($requestBody),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$response = json_decode($json_response, true);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice, status is:" . $status . "\nerror text is --> ";
print_r($response); echo "\n";
exit(-1);
}
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
//--- display results
echo "Document is sent! Envelope ID = " . $envelopeId . "\n\n";
?>
我要注意的最后一件事是确保你正在为这个电话而不是POST做PUT请求,因为这是我在这里看到的常见错误。