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;
}