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 curl_exec() failed, so you should call curl_error() to get the error message. – Olivier Commented Mar 6 at 8:33
  • You have a space at the beginning of the URL. – Olivier Commented Mar 6 at 8:45
Add a comment  | 

1 Answer 1

Reset to default 0

The 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