Reputation: 45
i want to download signed document from docusign .I created a new envelopeid for this.Is this the right way to download the document??I have also tried with the existing envelopeid which is used for document signing.While using the existing envelopeid,i m getting an authentication exception.
*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())
);
}*
Upvotes: 0
Views: 124
Reputation: 49104
If you want to download the signed document(s) from an existing envelope, you use the existing envelope's ID. See docs for EnvelopeDocuments::get
See the code examples that start with eg-03 in github.com/docusign
See workflow examples 6 and 7.
Upvotes: 1