使用 PHP 的 DocusignAPI 身份验证:"Integrator key was not specified"
DocusignAPI Authentication with PHP: "Integrator key was not specified"
我正在处理我的第一个 DocuSign API 实现,但我在向 REST API.
进行身份验证时遇到了问题
根据 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 未经授权”响应,其中包含 body:
'{
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}'
我很确定我正在设置 IntegratorKey header。我的 PHP 代码如下所示:
$request = new \http\Client\Request('GET', $url, $this->getHeaders());
$client = new \http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse();
我正在使用 pecl/http-v2 HTTP 库(文档位于:http://devel-m6w6.rhcloud.com/mdref/http)
$url 计算结果为:'https://demo.docusign.net/restapi/v2/login_information'
header 数组如下所示:
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 密钥,尽管我可以看到正在发送正确的 header。知道我在这里做错了什么吗?感谢您的帮助!
编辑: 修复了身份验证 header 中密码字段周围缺失的 double-quote。我在编辑密码时不小心删除了它。身份验证 header 将 character-for-character 与(工作)'curl' 命令中使用的 header 相匹配。
请查看 How should the header X-DocuSign-Authentication be used for REST and 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" )
);
至此,我使用的 HTTP 库似乎是问题的根源。我切换到 GuzzleHttp 并且 API 调用没有问题。
我怀疑我指定 headers 的数组的格式不正确。它可能是 key => value 格式,但我没有 time/interest 来测试它。 Guzzle 似乎更现代并且正在工作,所以我没有费心回到 pecl 包。
我正在处理我的第一个 DocuSign API 实现,但我在向 REST API.
进行身份验证时遇到了问题根据 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 未经授权”响应,其中包含 body:
'{
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}'
我很确定我正在设置 IntegratorKey header。我的 PHP 代码如下所示:
$request = new \http\Client\Request('GET', $url, $this->getHeaders());
$client = new \http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse();
我正在使用 pecl/http-v2 HTTP 库(文档位于:http://devel-m6w6.rhcloud.com/mdref/http)
$url 计算结果为:'https://demo.docusign.net/restapi/v2/login_information'
header 数组如下所示:
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 密钥,尽管我可以看到正在发送正确的 header。知道我在这里做错了什么吗?感谢您的帮助!
编辑: 修复了身份验证 header 中密码字段周围缺失的 double-quote。我在编辑密码时不小心删除了它。身份验证 header 将 character-for-character 与(工作)'curl' 命令中使用的 header 相匹配。
请查看 How should the header X-DocuSign-Authentication be used for REST and 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" )
);
至此,我使用的 HTTP 库似乎是问题的根源。我切换到 GuzzleHttp 并且 API 调用没有问题。
我怀疑我指定 headers 的数组的格式不正确。它可能是 key => value 格式,但我没有 time/interest 来测试它。 Guzzle 似乎更现代并且正在工作,所以我没有费心回到 pecl 包。