admin管理员组文章数量:1406308
I am trying to upgrade some older code that uses Docusign's username/password method of authentication for their Rest API to the newer OAuth version. We're using this for an automated service so JWT makes sense. Our existing code uses a prebuilt template in the Docusign account and populates it and sends it to the recipient. I have created a JWT Bearer Token and tried implementing it using cURL but I just get the response "false". I am at a loss here. Docusign hasn't been much help so far, their documentation is overwhelming. This runs in a Wordpress functions.php file, it should be simple. i worked for years the old way.
$fields = [];
$initials = [];
$checkboxes = [];
$recipients = ['[email protected]'];
$templateID = "2ce6c87b-****";
$accountId = '0cec5847-****';
$integratorKey = "d2c3fbe6-****";
$data = array(
'accountId' => $accountID,
'templateId' => $templateID,
'templateRoles' => $recipients,
'emailSubject' => 'Important Forms',
'status' => 'sent',
);
$data_string = json_encode($data);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => ' .1/accounts/123456789/envelopes',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data_string,
CURLOPT_HTTPHEADER => array ('Authorization: Bearer eyJ0****'),
));
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo json_encode($response);
curl_close($curl);
I am expecting some response from the cUrl call, even a 404. I literally get "false".
I am trying to upgrade some older code that uses Docusign's username/password method of authentication for their Rest API to the newer OAuth version. We're using this for an automated service so JWT makes sense. Our existing code uses a prebuilt template in the Docusign account and populates it and sends it to the recipient. I have created a JWT Bearer Token and tried implementing it using cURL but I just get the response "false". I am at a loss here. Docusign hasn't been much help so far, their documentation is overwhelming. This runs in a Wordpress functions.php file, it should be simple. i worked for years the old way.
$fields = [];
$initials = [];
$checkboxes = [];
$recipients = ['[email protected]'];
$templateID = "2ce6c87b-****";
$accountId = '0cec5847-****';
$integratorKey = "d2c3fbe6-****";
$data = array(
'accountId' => $accountID,
'templateId' => $templateID,
'templateRoles' => $recipients,
'emailSubject' => 'Important Forms',
'status' => 'sent',
);
$data_string = json_encode($data);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => ' https://demo.docusign/restapi/v2.1/accounts/123456789/envelopes',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data_string,
CURLOPT_HTTPHEADER => array ('Authorization: Bearer eyJ0****'),
));
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo json_encode($response);
curl_close($curl);
I am expecting some response from the cUrl call, even a 404. I literally get "false".
Share Improve this question edited Mar 6 at 5:45 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Mar 6 at 3:20 occitan occitan 12 bronze badges 2 |1 Answer
Reset to default 0The code appears to hardcode many things, and that may or may not be the issue.
First I see this:
CURLOPT_URL => ' https://demo.docusign/restapi/v2.1/accounts/123456789/envelopes',
The 123456789 is, I assume, your accountID, is this a GUID? or a short numeric value? are you sure you have the right accountID in there?
Then I see this:
CURLOPT_HTTPHEADER => array ('Authorization: Bearer eyJ0****'),
First, do you hardcode a token? that won't work, tokens expire after 8 hours. If you don't do that, how do you obtain it using JWT? do you have a consistent code that does this every time you need one? I would suggest trying to use the PHP SDK that does this for you. You can find this code in https://github/docusign/code-examples-php/blob/master/JWTConsoleApp/JWTConsoleApp.php
Third, I suggest you have code like this:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization': 'someAuthorization',
'x-api-key': 'somekey',
'Content-Type': 'application/x-www-form-urlencoded'
));
You need to set multiple headers, not just one
These headers are also needed:
'--header' "Accept: application/json" \
'--header' "Content-Type: application/json")
本文标签: phpDocusign Rest API Creating an Envelope Using JWT CredentialsStack Overflow
版权声明:本文标题:php - Docusign Rest API: Creating an Envelope Using JWT Credentials - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744998216a2636811.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
curl_exec()
failed, so you should callcurl_error()
to get the error message. – Olivier Commented Mar 6 at 8:33