首页 > 解决方案 > 如何将文档传递给 DocuSign Java SDK 的 updateDocument 方法

问题描述

我对使用 DocuSign 比较陌生,我正在尝试使用它发送电子邮件。

我想使用 Java SDK 在 DocuSign 中创建和更新信封。

我可以使用 templateId 创建一个信封,现在我想使用 documentId 替换信封中的一个文档。

我可以使用此处记录的其余 api 来做到这一点。它表示文档正文作为请求正文发送。文档中提到的 SDK 方法是Envelopes::updateDocument.

但是当我尝试使用 SDK 时,updateDocument只需要三个参数,签名是

public void updateDocument(String accountId, String envelopeId, String documentId) 抛出 ApiException {...}

那么我们如何使用 SDK 传递文档正文以更新信封中的文档?

标签: javadocusignapi

解决方案


一种有效的方法是定义您的文档,将您的文档添加到信封定义中,然后调用 updateDocuments 方法传递您的信封定义。

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

推荐阅读