我正在进行我的第一个DocuSign API实现,并且在向REST进行身份验证时遇到了问题。
遵循API文档,我可以通过在命令行上使用curl成功地进行身份验证:
$ curl --request GET 'https://demo.docusign.net/restapi/v2/login_information' --header 'Content-Type:application/json' --header 'Accept:application/json' --header 'X-DocuSign-Authentication:{"<redacted>", "Password": "<redacted>", "IntegratorKey": "<redacted>"}'
{
"loginAccounts": [
{
"name": "<redacted>",
"accountId": "<redacted>",
"baseUrl": "https://demo.docusign.net/restapi/v2/accounts/<redacted>",
"isDefault": "true",
"userName": "<redacted>",
"userId": "<redacted>",
"email": "<redacted>",
"siteDescription": ""
}
]然而,当我试图通过PHP使用HTTP请求进行身份验证时,我会收到一个'401未经授权‘响应,它的主体是:
'{
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}'我很确定我正在设置一个IntegratorKey头。我的PHP代码如下所示:
$request = new \http\Client\Request('GET', $url, $this->getHeaders());
$client = new \http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse();我使用的是pecl/ HTTP -v2HTTP库(文档位于:http://devel-m6w6.rhcloud.com/mdref/http )
$url级别到:'https://demo.docusign.net/restapi/v2/login_information'
头数组如下所示:
array (size=3)
0 => string 'X-DocuSign-Authentication: {"Username": "<redacted>", "Password": "<redacted>", "IntegratorKey": "<redacted>"}' (length=155)
1 => string 'Content-Type: application/json' (length=30)
2 => string 'Accept: application/json' (length=24)似乎API键没有被接收,尽管我可以看到正确的头正在被发送。知道我在这里做错什么了吗?谢谢你的帮忙!
编辑:修正了认证头中密码字段中缺少的双引号.我在修改密码时不小心把它删除了。身份验证头将字符对字符与(工作)“curl”命令中使用的标头匹配。
发布于 2015-01-13 16:30:40
此时,我使用的HTTP库似乎是问题的根源。我切换到了GuzzleHttp,API调用工作正常,没有问题。
我怀疑指定标头的数组没有以正确的格式给出。它本来可以是一种关键的=>值格式,但我没有时间/兴趣来测试它。口香糖似乎更现代,并正在发挥作用,所以我没有费心回到果胶包。
发布于 2015-01-06 23:32:52
请查看如何将报头用于REST和SOAP?,因为我认为您的“(引号")缺少了json "key”:“value”.
它怀疑这个样本可能从http://iodocs.docusign.com/APIWalkthrough/requestSignatureFromTemplate提供给您:
$data = array("accountId" => $accountId,
"emailSubject" => "DocuSign API - Signature Request from Template",
"templateId" => $templateId,
"templateRoles" => array(
array( "email" => $email, "name" => $recipientName, "roleName" => $templateRoleName )),
"status" => "sent");
$data_string = json_encode($data);
$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" )
);https://stackoverflow.com/questions/27807757
复制相似问题