Reputation: 420
I'm relatively new to using DocuSign and I'm trying to send emails using it.
I want to create and update envelopes in DocuSign using the Java SDK.
I'm able to create an envelope using templateId and now I want to replace one of the documents in the envelope using documentId.
I'm able to do it using the rest api as documented here. It says that the document body is sent as the request body. And the SDK method mentioned in the documentation for this is Envelopes::updateDocument
.
But when I tried using the SDK, updateDocument
takes only three parameters, the signature is
public void updateDocument(String accountId, String envelopeId, String documentId) throws ApiException {...}
So how do we pass the document body using the SDK in order to update a document in an envelope ?
Upvotes: 0
Views: 590
Reputation: 111
An approach that works is to define your document, add your document to an envelopeDefinition and then call the updateDocuments method passing your envelopeDefintion.
public static String AddDocument(ApiClient apiClient, String envelopeId, String accountId, String docPath)
{
try {
String retVal;
EnvelopesApi api = new EnvelopesApi(apiClient);
//******************* Add Document*********************
ArrayList documents = new ArrayList<Document>();
byte[] fileBytes = null;
Document doc = new Document();
Path path = Paths.get(docPath);
fileBytes = Files.readAllBytes(path);
doc.setName("Stop Payment Request");
String base64Doc = Base64.encodeToString(fileBytes, false);
doc.setDocumentBase64(base64Doc);
doc.setDocumentId("1");
doc.setFileExtension( "pdf");
documents.add(doc);
EnvelopeDefinition envelope1 = new EnvelopeDefinition();
envelope1.setDocuments(documents);
EnvelopeDocumentsResult result = api.updateDocuments(accountId, envelopeId, envelope1);
retVal = result.getEnvelopeId();
return retVal;
}
catch(Exception e)
{
return e.getMessage();
}
}
Upvotes: 1