Downloading the completed document
- The ID of the completed document must be stored.
- Use the download document call to download the document. If the document has only one file, this will download the file as a PDF. If there are multiple files, a zip file containing all the files will be downloaded.
- If there are multiple files, use the document_id for all the files in the document and call /api/v1/requests/<request_id>/documents/<document_id>/pdf.
- If you would like to download the certificate of completion for the document, you can use the downloadcompletion certificate call.
<?php
$curl = curl_init("https://sign.zoho.com/api/v1/requests/<Request-Id>/completioncertificate");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization:Zoho-oauthtoken <Oauth-Token>',
"Content-Type:multipart/form-data"
));
curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$filePath="<File-path>";
$fp = fopen ( $filePath, 'w+');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
}
);
$response = curl_exec($curl);
curl_close($curl);
?>
const express = require('express');
const fs = require('fs');
const fetch = require('node-fetch');
const path = require('path');
const app = express();
const port = 4000;
app.get('/downloadCompletionCertificate', async (req, res) => {
let HEADERS = {};
HEADERS['Authorization'] = 'Zoho-oauthtoken <Oauth Token>';
let URL = 'https://sign.zoho.com/api/v1/requests/<Request-Id>/completioncertificate';
let method = 'GET';
let requestOptions = {
method: method,
headers: HEADERS
};
return await fetch(URL, requestOptions)
.then((_res) => {
console.log(`Return code is ${_res.status}`);
let contentDisposition = _res.headers.get('content-disposition');
if (contentDisposition !== null) {
let filename = contentDisposition.split(';')[1].split('=')[1].replace(/\"/g, '').replace("UTF-8''", '');
let filepath = '<File-Path>';
if (!fs.existsSync(filepath + filename)) {
fs.mkdirSync(filepath, { recursive: true });
}
let fileStream = fs.createWriteStream(path.join(filepath, filename));
_res.body.pipe(fileStream);
res.send('downloaded');
return _res;
}
return _res.json().then((responseJson) => {
return responseJson;
});
})
.catch((error) => {
let errorResponse = {};
errorResponse['message'] = 'call failed to initiate'; //check internet connection or proper DC type
errorResponse['status'] = 'failure';
res.send(errorResponse);
});
});
app.listen(port, () => {
console.log(`Example app listening on port {port}`);
});
<response> = zoho.sign.downloadDocument(<requestID>,[<connection>]);
<response_2> = invokeurl
[
url :"https://sign.zoho.com/api/v1/requests/requestID/completioncertificate"
type :GET
connection : "[<connection>]"
];
JSONObject documentJson = temp.getJSONObject("requests");
String docStatus = documentJson.getString("request_status");
if(docStatus.equals("completed"))
{
//Check if single or multiple documents
JSONArray documentIds = documentJson.getJSONArray("document_ids");
if(documentIds.length() == 1)
{
//Download single document directly
getMethod = new HttpGet("https://sign.zoho.com/api/v1/requests/"+requestId+"/pdf");
response = client.execute(getMethod);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String filePath = "C:\\Users\\windowsUserName\\Downloads\\"+documentJson.getString("request_name");
FileOutputStream fos = new FileOutputStream(new File(filePath));
byte[] buffer = new byte[5600];
int inByte;
while((inByte = is.read(buffer)) > 0)
fos.write(buffer,0,inByte);
is.close();
fos.close();
}
else
{
for(int i=0; i< documentIds.length(); i++)
{
String documentId = documentIds.getJSONObject(i).getString("document_id");
getMethod = new HttpGet("https://sign.zoho.com/api/v1/requests/"+requestId+"/documents/"+documentId+"/pdf");
response = client.execute(getMethod);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String filePath = "C:\\Users\\windowsUserName\\Downloads\\"+documentIds.getJSONObject(i).getString("document_name");
FileOutputStream fos = new FileOutputStream(new File(filePath));
byte[] buffer = new byte[5600];
int inByte;
while((inByte = is.read(buffer)) > 0)
fos.write(buffer,0,inByte);
is.close();
fos.close();
}
}
//Download Completion certificate
getMethod = new HttpGet("https://sign.zoho.com/api/v1/requests/"+requestId+"/completioncertificate");
response = client.execute(getMethod);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String filePath = "C:\\Users\\windowsUserName\\Downloads\\"+documentJson.getString("request_name")+"_completioncertificate.pdf";
FileOutputStream fos = new FileOutputStream(new File(filePath));
byte[] buffer = new byte[5600];
int inByte;
while((inByte = is.read(buffer)) > 0)
fos.write(buffer,0,inByte);
is.close();
fos.close();
}
def getDownloadPDF(request_id,Oauthtoken):
headers = {'Authorization':'Zoho-oauthtoken '+Oauthtoken}
r = requests.get('https://sign.zoho.com/api/v1/requests/'+request_id+"/pdf",headers=headers)
open('temp.pdf', 'wb').write(r.content)
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://sign.zoho.com/api/v1/requests/"+ <<requestId>> + "/pdf");
httpWebRequest.Method = "GET";
httpWebRequest.Headers["Authorization"] = "Zoho-oauthtoken " + <<accessToken>>;
using (HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream output = File.OpenWrite("ZohoSignDocument.pdf"))
using (Stream input = response.GetResponseStream())
{
input.CopyTo(output);
output.Close();
}
}
Show full
Show less