docusign / docusign-esign-php-client

The Official Docusign PHP Client Library used to interact with the eSign REST API. Send, sign, and approve documents using this client.
https://www.docusign.com/devcenter
MIT License
196 stars 123 forks source link

How to void an envelope ? #190

Closed bastien70 closed 1 year ago

bastien70 commented 1 year ago

Hello, I'm trying to void an envelope, like this :

    public function cancelEnvelope(
        string $envelopeId,
        string $reason,
    )
    {
        $envelopesApi = new EnvelopesApi($this->login());

        try {
            $envelope = $envelopesApi->getEnvelope($this->docuSignUserAccountId, $envelopeId);
            $envelope->setVoidedReason($reason);
            $envelope->setStatus('voided');
            $envelopesApi->update($this->docuSignUserAccountId, $envelopeId, $envelope);
        } catch (ApiException $e) {
            throw new \RuntimeException($e->getMessage());
        }
    }

But I've the following error :

Error while requesting server, received a non successful HTTP code [400] with response Body: O:8:"stdClass":2:{s:9:"errorCode";s:25:"INVALID_REQUEST_PARAMETER";s:7:"message";s:209:"The request contained at least one invalid parameter. Value for 'purgeState' must be 'documents_queued' or 'documents_and_metadata_queued' or 'documents_dequeued' or 'documents_and_metadata_and_redact_queued'.";}

How to fix this please ?

dmartin00 commented 1 year ago

Right now you're pulling in the whole envelope definition and passing that back, which the DocuSign API interprets as an attempt to touch a value that you can't change. A better way to approach this is to send an envelope definition that has nothing except "status":"voided" and the voidReason.

Remove the GetEnvelope line of your code and replace that with an empty envelope definition instead, while leaving the SetVoidedReason and SetStatus, and you should see this start working.

bastien70 commented 1 year ago

Oh okay, but I think you would like to say A better way to approach this is to send an ENVELOPE that has nothing except "status":"voided" and the voidReason. and not an ENVELOPE DEFINITION ?

So, I did :

    public function cancelEnvelope(
        string $envelopeId,
        string $reason,
    )
    {
        $envelopesApi = new EnvelopesApi($this->login());

        try {
            $envelope = new Envelope();
            $envelope->setVoidedReason($reason)
                ->setStatus('voided');

            $envelopesApi->update($this->docuSignUserAccountId, $envelopeId, $envelope);
        } catch (ApiException $e) {
            throw new \RuntimeException($e->getMessage());
        }
    }

And it seemd to work ! :) Thank you!