问题
With the following code I am able to read the template from my account and send an email with that template is working.
EnvelopesApi envelopesApi1 = createEnvelopesApi(basePath,
prop.getProperty("authenticationToken"));
EnvelopeDefinition envelope1 = makeEnvelope(signerEmail, signerName);
EnvelopeSummary result = envelopesApi1.createEnvelope(accountId, envelope1);
// session.setEnvelopeId(result.getEnvelopeId());
DoneExample.createDefault("Cusotm title")
.withJsonObject(result)
.withMessage("The envelope has been created and sent!<br/>Envelope ID "
+ result.getEnvelopeId() + ".")
.addToModel(model);
But my application is embedded application, so the approval needs to be done over application Hence I have tried to integrate the same in my embedded application.But I am getting error. My code is below.
// Next, create the top level envelope definition and populate it.
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
envelopeDefinition.setEmailSubject("Please sign this document!!");
envelopeDefinition.setEmailBlurb("this is the custom mail content");
//envelopeDefinition.setDocuments(Arrays.asList(document));
envelopeDefinition.setTemplateId("6fcd32d8-91f6-4f4f-90f8-8b54eb71bfb8");
envelopeDefinition.setTemplateRoles(Arrays.asList(signer1));
// Add the recipient to the envelope object
Recipients recipients = new Recipients();
//recipients.setSigners(Arrays.asList(signer));
//envelopeDefinition.setRecipients(recipients);
envelopeDefinition.setStatus("sent");
// requests that the envelope be created and sent.
// Step 2. Call DocuSign to create and send the envelope
ApiClient apiClient = new ApiClient(basePath);
apiClient.setAccessToken(accessToken, tokenExpirationSeconds);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
EnvelopeSummary results = envelopesApi.createEnvelope(accountId, envelopeDefinition);
String envelopeId = results.getEnvelopeId();
// Step 3. The envelope has been created.
// Request a Recipient View URL (the Signing Ceremony URL)
RecipientViewRequest viewRequest = new RecipientViewRequest();
// Set the url where you want the recipient to go once they are done signing
// should typically be a callback route somewhere in your app.
viewRequest.setReturnUrl(baseUrl + "/ds-return");
viewRequest.setAuthenticationMethod(authenticationMethod);
viewRequest.setEmail(signerEmail);
viewRequest.setUserName(signerName);
viewRequest.setClientUserId(clientUserId);
// call the CreateRecipientView API
ViewUrl results1 = envelopesApi.createRecipientView(accountId, envelopeId, viewRequest);
// Step 4. The Recipient View URL (the Signing Ceremony URL) has been received.
// The user's browser will be redirected to it.
String redirectUrl = results1.getUrl();
redirect = new RedirectView(redirectUrl);
redirect.setExposeModelAttributes(false);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return redirect;
}
Here I am getting the below error.
com.docusign.esign.client.ApiException:
Error while requesting server, received a non successful
HTTP code 400 with response Body:
'{"errorCode":"UNKNOWN_ENVELOPE_RECIPIENT",
"message":"The recipient you have identified is not a valid
recipient of the specified envelope."}'
at com.docusign.esign.client.ApiClient.invokeAPI(ApiClient.java:1177)
~[docusign-esign-java-3.2.0.jar:na]
at com.docusign.esign.api.EnvelopesApi.createRecipientView(EnvelopesApi.java:1262)
~[docusign-esign-java-3.2.0.jar:na]
....
回答1:
There are two ways to solve this problem, one is my below alternate way and the second one is as Larry suggested in the comment just add the clientUserId to the signer recipient when you send the envelope.
For embedded sign we need to go for CompositeTemplate
private EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, String clientUserId, WorkArguments args) throws IOException {
CarbonCopy cc1 = new CarbonCopy();
cc1.setEmail("mail");
cc1.setName("name");
cc1.setRoleName(EnvelopeHelpers.CC_ROLE_NAME);
cc1.setRecipientId("2");
// create a composite template for the server template
CompositeTemplate compTemplate1 = new CompositeTemplate();
compTemplate1.setCompositeTemplateId("1");
ServerTemplate serverTemplates = new ServerTemplate();
serverTemplates.setSequence("1");
serverTemplates.setTemplateId("dafgs345-546sdf4-3546sdfqew");
compTemplate1.setServerTemplates(Arrays.asList(serverTemplates));
// Add the roles via an inlineTemplate object
InlineTemplate inlineTemplate = new InlineTemplate();
inlineTemplate.setSequence("1");
inlineTemplate.setRecipients(EnvelopeHelpers.createRecipients(createSigner(signerEmail,signerName,clientUserId), cc1));
compTemplate1.setInlineTemplates(Arrays.asList(inlineTemplate));
// The signer recipient for the added document with a tab definition
Tabs signer1Tabs = EnvelopeHelpers.createSingleSignerTab("**signature_1**", ANCHOR_OFFSET_Y, ANCHOR_OFFSET_X);
signer1Tabs.textTabs(Arrays.asList(
createText("text", "453", "110","Customized data"),
createText("numbersOnly", "453", "130", "147896")));
Signer signer1AddedDoc = createSigner(signerEmail, signerName,clientUserId);
signer1AddedDoc.setAccessCode("12345");
signer1AddedDoc.setTabs(signer1Tabs);
// Create the HTML document
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args);
// Create a composite template for the added document and add the recipients via an inlineTemplate
CompositeTemplate compTemplate2 = new CompositeTemplate();
compTemplate2.setCompositeTemplateId("2");
InlineTemplate inlineTemplate2 = new InlineTemplate();
inlineTemplate2.setSequence("2");
inlineTemplate2.setRecipients(EnvelopeHelpers.createRecipients(signer1AddedDoc, cc1));
compTemplate2.setInlineTemplates(Arrays.asList(inlineTemplate2));
compTemplate2.setDocument(EnvelopeHelpers.createDocument(htmlDoc, HTML_DOCUMENT_NAME,
DocumentType.HTML.getDefaultFileExtention(), "1"));
EnvelopeDefinition env = new EnvelopeDefinition();
env.setStatus(EnvelopeHelpers.ENVELOPE_STATUS_SENT);
env.setCompositeTemplates(Arrays.asList(compTemplate1, compTemplate2));
return env;
}
and then we can call the api
EnvelopeDefinition envelope = makeEnvelope(signerEmail, signerName, clientUserId, args);
EnvelopeSummary envelopResults = envelopesApi2.createEnvelope(accountId, envelope);
RecipientViewRequest viewRequest1 = makeRecipientViewRequest(args);
ViewUrl viewUrl = envelopesApi2.createRecipientView(accountId, envelopResults.getEnvelopeId(), viewRequest1);
return new RedirectView(viewUrl.getUrl());
来源:https://stackoverflow.com/questions/62873306/the-recipient-you-have-identified-is-not-a-valid-recipient-of-the-specified-enve