Docusignapi 如何使用envelopeid-java从docusign下载签名文档

Docusignapi 如何使用envelopeid-java从docusign下载签名文档,docusignapi,Docusignapi,我想从docusign下载已签名的文档。我为此创建了一个新的信封ID。这是下载文档的正确方法吗?我还尝试了用于文档签名的现有信封ID。在使用现有信封ID时,我遇到了身份验证异常 *JSONObject json=null; String accessToken = null; try (CloseableHttpClient httpclient = HttpClients.createDefault()) { L

我想从docusign下载已签名的文档。我为此创建了一个新的信封ID。这是下载文档的正确方法吗?我还尝试了用于文档签名的现有信封ID。在使用现有信封ID时,我遇到了身份验证异常

 *JSONObject json=null;
            String accessToken = null;
            try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
                List<NameValuePair> form = new ArrayList<>();
                form.add(new BasicNameValuePair("scope", "api"));
                form.add(new BasicNameValuePair("username", docUsername));
                form.add(new BasicNameValuePair("password", docPassword));
                form.add(new BasicNameValuePair("grant_type", docGranttype));
                form.add(new BasicNameValuePair("client_id", docClientId));
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
                HttpPost httpPost = new HttpPost(docTokenurl);
                httpPost.setEntity(entity);
                System.out.println("Executing request " + httpPost.getRequestLine());
                // Create a custom response handler
                ResponseHandler<String> responseHandler = response -> {
                    int status = response.getStatusLine().getStatusCode();
                    if (status >= 200 && status < 300) {
                        HttpEntity responseEntity = response.getEntity();
                        return responseEntity != null ? EntityUtils.toString(responseEntity) : null;
                    } else {
                        throw new ClientProtocolException("Unexpected response status: " + status);
                    }
                };
                String responseBody = httpclient.execute(httpPost, responseHandler);
                System.out.println("----------------------------------------");
                System.out.println(responseBody);
                json = new JSONObject(responseBody);
                accessToken = json.getString("access_token");


            String accountId = docAccountId;
            EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();

            ApiClient apiClient = new ApiClient(docBasePath);
            apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
            EnvelopeSummary results = envelopesApi.createEnvelope(accountId, envelopeDefinition);
            String envelopeId = results.getEnvelopeId();

            EnvelopeDocumentsResult docsList = envelopesApi.listDocuments(docAccountId, envelopeId);
            for( EnvelopeDocument doc: docsList.getEnvelopeDocuments() ) {

                Files.write(
                        new File(doc.getName()).toPath(),envelopesApi.getDocument(docAccountId, envelopeId, doc.getDocumentId())
                        );
            }*
*JSONObject json=null;
字符串accessToken=null;
try(CloseableHttpClient-httpclient=HttpClients.createDefault()){
列表形式=新建ArrayList();
添加(新的BasicNameValuePair(“范围”、“api”);
添加(新的BasicNameValuePair(“用户名”,docUsername));
添加(新的BasicNameValuePair(“密码”,docPassword));
添加(新的BasicNameValuePair(“grant_类型”,docGranttype));
添加(新的BasicNameValuePair(“客户id”,docClientId));
UrlEncodedFormEntity实体=新的UrlEncodedFormEntity(表单,Consts.UTF_8);
HttpPost HttpPost=新的HttpPost(docTokenurl);
httpPost.setEntity(实体);
System.out.println(“正在执行请求”+httpPost.getRequestLine());
//创建自定义响应处理程序
ResponseHandler ResponseHandler=响应->{
int status=response.getStatusLine().getStatusCode();
如果(状态>=200&&status<300){
HttpEntity responseEntity=response.getEntity();
return responseEntity!=null?EntityUtils.toString(responseEntity):null;
}否则{
抛出新的ClientProtocolException(“意外响应状态:+状态”);
}
};
字符串responseBody=httpclient.execute(httpPost,responseHandler);
System.out.println(“--------------------------------------------------------”;
系统输出打印LN(响应库);
json=新的JSONObject(responseBody);
accessToken=json.getString(“访问令牌”);
字符串accountId=docAccountId;
信封定义信封定义=新信封定义();
ApiClient ApiClient=新的ApiClient(docBasePath);
apiClient.addDefaultHeader(“授权”、“承载人”+accessToken);
信封API信封API=新信封API(apiClient);
EnvelopesSummary results=envelopesApi.createEnvelope(accountId,EnvelopedDefinition);
字符串envelopeId=results.getEnvelopeId();
EnvelopedDocumentsResult docsList=envelopesApi.listDocuments(docAccountId,envelopeId);
对于(信封文档文档:docsList.getEnvelopedDocuments()){
文件。写入(
新文件(doc.getName()).toPath(),信封API.getDocument(docAccountId,信封ID,doc.getDocumentId())
);
}*

如果要从现有信封下载签名文档,请使用现有信封的ID。有关详细信息,请参阅文档

请参阅github.com/docusign中以eg-03开头的代码示例

请参见工作流示例6和7