我在调用webservice时出现此错误,状态为:401当我创建一个新帐户的成员帐户(非开发人员帐户并尝试将其集成到我拥有的表单中时...基于docusign中的api演练的代码本身
<?php
if(($_POST['submit']))
{
// Input your info here:
$integratorKey = 'XXXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX';
$email = 'XXXXXXXXXX';
$email1 = 'XXXXXXXXX';
$email2 = 'XXXXXXXX';
$password = 'XXXXXXXX';
$name = 'XXX';
$name2 = 'XXXXXX';
// 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
/////////////////////////////////////////////////////////////////////////////////////////// //////
// STEP 2 - Create an envelope with one recipient, one tab, one document and send!
/////////////////////////////////////////////////////////////////////////////////////////// //////
$data = "{
\"emailBlurb\":\"This comes from Dateguard\",
\"emailSubject\":\"DocuSign API - Please Sign This Contract for Dateguard...\",
\"documents\":[
{
\"documentId\":\"1\",
\"name\":\"contract.pdf\"
}
],
\"recipients\":{
\"signers\":[
{
\"email\":\"$email1\",
\"name\":\"$name\",
\"recipientId\":\"1\",
\"tabs\":{
\"signHereTabs\":[
{
\"xPosition\":\"80\",
\"yPosition\":\"550\",
\"documentId\":\"1\",
\"pageNumber\":\"1\"
}
]
}
},
{
\"email\":\"$email2\",
\"name\":\"$name2\",
\"recipientId\":\"2\",
\"tabs\":{
\"signHereTabs\":[
{
\"xPosition\":\"400\",
\"yPosition\":\"550\",
\"documentId\":\"1\",
\"pageNumber\":\"1\"
}
]
}
}
]
},
\"status\":\"sent\"
}";
$file_contents = file_get_contents("contract.pdf");
$requestBody = "\r\n"
."\r\n"
."--myboundary\r\n"
."Content-Type: application/json\r\n"
."Content-Disposition: form-data\r\n"
."\r\n"
."$data\r\n"
."--myboundary\r\n"
."Content-Type:application/pdf\r\n"
."Content-Disposition: file; filename=\"contract.pdf\"; documentid=1 \r\n"
."\r\n"
."$file_contents\r\n"
."--myboundary--\r\n"
."\r\n";
// *** 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, $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);
$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
$home_url = 'thanks.php';
header('Location: ' . $home_url);
}
?>
现在的问题是,当我在docusign中使用我的开发者帐户作为其工作的api的凭据但是当我创建一个成员帐户时它没有(免费试用)..它应该以这种方式工作吗?我错过了什么?如果它是那么我应该如何使用api工作,以便成员使用自己的帐户并使用自己的凭据,并能够在docusign api中使用它,而不是我自己的开发者帐户,因为“测试”指示。提前谢谢。
答案 0 :(得分:1)
401需要授权
如果代码适用于开发者帐户,那么原因应该是帐户权限。
答案 1 :(得分:0)
在DocuSign免费试用帐户上未启用API - 它在免费的开发者沙箱帐户上启用(30天后不会过期)。创建这些帐户的唯一方法是DocuSign Developer Center。
当然,如果你有一个实时集成,意味着你通过DocuSign认证,那么你可能有一个生产帐户启用了api,但在你开发和测试时,你只能使用开发者帐户,而不是免费试用。