0
votes

I'm trying to use the DocuSign PHP SDK to send a signing request based on a template. I am attempting to follow the steps outlined in this example: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote

To authenticate, I am using a JWT. I assembled a header and payload signed with RSA256 private key generated by DocuSign, and the access token I received in response is in this format: eyJ0eXAiOiJ-----.yyyyyy-----.zzzzzz----- (Example, actual token is much longer).

When I try to run this code here (putting in the above access token and my DocuSign credentials as the arguments):

private function worker($args)
{
    $envelope_args = $args["envelope_args"];
    # Create the envelope request object
    $envelope_definition = $this->make_envelope($envelope_args);
    # Call Envelopes::create API method
    # Exceptions will be caught by the calling function
    $config = new \DocuSign\eSign\Configuration();
    $config->setHost($args['base_path']);
    $config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
    $api_client = new \DocuSign\eSign\client\ApiClient($config);
    $envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
    try {
        $results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
        $envelope_id = $results->getEnvelopeId();
    }
    catch(ApiException $apiException) {
        echo $apiException->getMessage();
    }
    return ['envelope_id' => $envelope_id];
}

Then I end up catching an exception:

Error while requesting server, received a non successful HTTP code [302] with response Body:

Digging a little deeper and var_dumping the response, the body is indeed empty and here are the response headers:

array(
  0 => string 'HTTP/1.1 302 Found'
  'Cache-Control' => string 'no-cache'
  'Content-length' => string '0'
  'Location' => string 'https://account-d.docusign.com/v2.1/accounts/6d7dc630-xxxx-xxxx-xxxx-xxxxxxxxxxxx/envelopes'
  'Connection' => string 'close'
)

I have blocked out the the number in the Location section of the response in case it's anything sensitive. Being new to the DS API, I am unclear what this number is. It's not anything I have defined in my configuration for the project.

Does anyone have any idea what this error message indicates? Am I trying to access an incorrect API endpoint? Does this indicate my JWT access token is invalid? Something else?

Thanks for any help you can provide.

1

1 Answers

0
votes

A better technique is to use the php quickstart and then copy the example that creates an envelope from a template

Re your current code: I'd check your base path.

Also check your access token. Your software is being redirected to the account server