How to create link for a recipient to sign an envelope via JWT authorisation

Viewed 22

I can successfully create envelopes from a template via api (JWT), but when I fetch the link for the envelope for the end user to sign, the document appears with "In progress" with no form fields attached to. The link received via email when the envelope is generated is correct with the form fields included.

I conclude from this that the recipient view returned is that of the admin user, and not the end user. How can I create a link for the actual user to sign?

I've pieced the following code together from various other SO posts since the documentation is pretty hard to navigate:

const options1 = {
        'method': 'GET',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
    }

const recipients = await this.apiCall(`accounts/${process.env.DOCUSIGN_ACCOUNT_ID}/envelopes/${envelopeId}/recipients`, options1);
        const userId = recipients.signers[0].userId;

        const options = {
            'method': 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                email: email,
                userName: "test test",
                userId: userId,
                authenticationMethod: 'email',
                returnUrl: `${process.env.FRONTEND_URL}/docusign-complete?type=${type}&cid=${consignmentId}`,
            })
        }
        
        const response = await this.apiCall(`accounts/${process.env.DOCUSIGN_ACCOUNT_ID}/envelopes/${envelopeId}/views/recipient`, options);

async apiCall(url, options){
    const accessToken = await this.getAccessToken();
    const userInfo = await this.getUserInfo(accessToken.access_token);
    options.headers['Authorization'] = `Bearer ${accessToken.access_token}`;
    const response = await fetch(`${userInfo.accounts[0].base_uri}/restapi/v2.1/${url}`, options);
    const responseJson = await response.json();
    return responseJson;
}

1 Answers

If you are referring to the Recipient View for Embedded Signing, here is a good example which walks through the entire process for creating an embedded signing view and generating the embedded signing URL

From what I can see in your code, it looks like you are passing the userId parameter retrieved from the getUsers call to the createRecipientView request whereas you need to set a special clientUserId parameter while creating the envelope which you in turn need to pass to the createRecipientView request. The example I linked earlier explains all of this.

The clientUserId parameter is what signifies to DocuSign that this is an embedded signer

Related