Search code examples
phplaravelpdfjwtdocusignapi

PHP DocuSign: getting empty document when downloading the completed signed document


I integrated Docusing with a PHP Laravel App using JWT Auth. It's working perfectly, could send the email to recipients for signing. Now after all signing is done we would like to download the complete signed document with CoC.

I'm using following code to get the signed document for a specific Envelope:

$envelope_api = new EnvelopesApi($apiClient);

$tmpFile = $envelope_api->getDocument($account_id, 'combined', $envelope_id);

$savCert = file_put_contents("signed_document.pdf", file_get_contents($tmpFile->getPathname()));

But I'm getting the empty document when the file is downloaded. It would very helpful if you could give a hint how to resolve the issue.

json payload for a $tmpfile:

object(SplFileObject)#418 (5) 
{
 ["pathName":"SplFileInfo":private]=> string(44) "C:\Users\AppData\Local\Temp\19F.tmp" 
 ["fileName":"SplFileInfo":private]=> string(7) "19F.tmp" 
 ["openMode":"SplFileObject":private]=> string(1) "r" 
 ["delimiter":"SplFileObject":private]=> string(1) "," 
 ["enclosure":"SplFileObject":private]=> string(1) """ 
}

Solution

  • This is a bug in version 6.5 of the SDK Version 6.5.1 has the fix. Please update your package and try again.

    If you use 6.5 you will need to add these lines:

    $tmpFile = $envelopeApi->getDocument($account_id, 'combined', $envelope_id);
    $tmpFile->rewind();
    $contents = $tmpFile->fread($tmpFile->fstat()['size']);