Get started with Zoho Sign's APIs in under two minutes

This section demonstrates how to send an envelope for signature request via email. 

Please ensure that you have created your OAuth token before trying this. Learn how to create an OAuth token based on your business needs.

  1. Upload this sample text tag document, which has one signer tag. Know more about text tags in Zoho Sign
  2. Add the recipient details like the recipient's mail id, name, set your signing order, and implement any additional settings, if needed.
  3. The associated text tags will be parsed to the corresponding document fields, and then the document will be sent to the recipient for signature.

The placeholders - <Access Token>, <Recipient Email>, <Recipient Name>,/home/local/document_name.pdf needs to be replaced with actual data.
 

Try Zoho Sign's API for free 
  • You can fully test our APIs by passing testing = true as a parameter in your API calls and can send up to 50 envelopes per month.
  • These envelopes will carry the watermark - "Powered by Zoho Sign. For testing purposes only" and hold no legal authority.

     

 

Copiedimport java.io.*;
import org.json.*; //json.jar
import org.apache.http.*; //httpclient-4.5.10.jar
import org.apache.http.entity.*;//httpcore-4.4.4.jar
import org.apache.http.entity.mime.*;//httpmime-4.5.2.jar
import org.apache.http.client.HttpClient;//httpclient-4.5.10.jar
import org.apache.http.client.methods.HttpPost;//httpclient-4.5.10.jar
import org.apache.http.impl.client.DefaultHttpClient;//httpclient-4.5.10.jar
import org.apache.http.util.EntityUtils;//httpcore-4.4.4.jar

public class CreateAndSubmit {
	
	public static void main (String args[]) throws Exception {
		
		//replace the below data with the values you want to make this functioning
		String recipientName = "<recipient_name>"; 
		String recipientEmail = "<recipient_email>";
		String accessToken = "<Access Token>";
		String filePath = "<path of the file>"; //"/home/local/document_name.pdf"
		
		String requestCreationUrl = "https://sign.zoho.com/api/v1/requests";
		String requestSubmitUrl = "https://sign.zoho.com/api/v1/requests/%s/submit";
	
		//Step 1 - Request Creation (Uploading document)
		JSONObject reqCreationJson = createRequest(requestCreationUrl, accessToken, filePath);
		if(reqCreationJson.getString("status").equals("success"))
		{
			//Step 2 - Submitting Request (Sending out for signature request)
			JSONObject reqSubmitJson = submitRequest(reqCreationJson.getJSONObject("requests"), requestSubmitUrl, accessToken, recipientEmail, recipientName);
			if(reqSubmitJson.has("status") && reqSubmitJson.getString("status").equals("success")) {
				System.out.println("Document sent successfully");
				System.out.println(reqSubmitJson);
			}
			else {
				System.out.println("Error : "+reqSubmitJson.toString());
			}
		}
		else {
			System.out.println("Error with creating document : "+reqCreationJson.toString());
		}
	}


	private static JSONObject createRequest(String requestCreationUrl, String accessToken, String filePath) throws Exception {
		JSONObject requestPayload = new JSONObject();
		requestPayload.put("request_name","testDoc");
		requestPayload.put("expiration_days",10);
		requestPayload.put("is_sequential", true);
		requestPayload.put("notes","Sign the document");
		
		HttpEntity multipart = multiPartBuilder(new JSONObject().put("requests", requestPayload), true, filePath);
		return httpPostCall(multipart, String.format(requestCreationUrl), accessToken);
	}
	
	private static JSONObject submitRequest(JSONObject requestsJson, String requestSubmitUrl, String accessToken, String recipientEmail, String recipientName) throws Exception {
		String requestId = requestsJson.getString("request_id");

		JSONObject actionJson = new JSONObject();
		actionJson.put("action_type","SIGN");
		actionJson.put("recipient_email", recipientEmail);
		actionJson.put("recipient_name", recipientName);
		actionJson.put("verify_recipient", false);
		actionJson.put("signing_order", 0);

		JSONObject dataJson = new JSONObject();
		dataJson.put("requests", new JSONObject().put("actions", new JSONArray().put(actionJson)));
		HttpEntity multipart = multiPartBuilder(dataJson, false, null);
		return httpPostCall(multipart, String.format(requestSubmitUrl, requestId), accessToken);
	}

	//used to make HTTP call to Sign API Endpoints
	private static JSONObject httpPostCall(HttpEntity multipart,String url,String accessToken) throws ParseException, IOException, JSONException {
		HttpClient client = new DefaultHttpClient();
		HttpPost postMethod = new HttpPost(url);
		postMethod.setHeader("Authorization","Zoho-oauthtoken "+accessToken);
		if(multipart != null)
			postMethod.setEntity(multipart);
		HttpResponse response = client.execute(postMethod); //API call
		String responseJSON = EntityUtils.toString(response.getEntity(), "UTF-8");
		return new JSONObject(responseJSON);
	}
	
	//this constructs HTTP entity to be passed while making HTTP calls in httpPostCall method
	private static HttpEntity multiPartBuilder(JSONObject dataJson, boolean addBinaryBody, String filePath) {
		MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
		if(addBinaryBody) {
			File firstFile = new File(filePath); //First file to be uploaded
			reqEntity.addBinaryBody("file",firstFile, ContentType.APPLICATION_OCTET_STREAM, "Test1.pdf");
		}
		reqEntity.addTextBody("data",dataJson.toString());
                //uncomment this if you are testing our API. Documents sent this way will carry a watermark and cannot be removed
		//reqEntity.addTextBody("testing", "true"); 
                 return reqEntity.build();
	}
}
Copied<?php
    //replace the below data with the values you want to make this functioning
    $recipientName = "<recipient_name>"; 
    $recipientEmail = "<recipient_email>";
    $accessToken = "<Access Token>";
    $filePath ="<path of the file>"; 


    //Step 1 - Request Creation (Uploading document)
    $requestPayload=new stdClass();
    $requestPayload->request_name="test doc";
    $requestPayload->expiration_days = 10;
    $requestPayload->is_sequential = true;
    $requestPayload->notes = "Sign the document";

    $request = new stdClass();
    $request->requests = $requestPayload;

    $data = json_encode($request);
    $POST_DATA = array(
        'data' => $data,
        'file' => new CURLfile($filePath) //First file to be uploaded
    );
    
    //used to make HTTP call to Sign API Endpoints
    $curl = curl_init("https://sign.zoho.com/api/v1/requests");
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Authorization:Zoho-oauthtoken '.$accessToken,
        "Content-Type:multipart/form-data"
    ));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
    $response = curl_exec($curl);
    curl_close($curl);

    $jsonbody = json_decode($response);
    if ($jsonbody->status == "success") {

        //Step 2 - Submitting Request (Sending out for signature request)
        $requestId = $jsonbody->requests->request_id;
        $createdRequest = new stdClass();
        $createdRequest = $jsonbody->requests;

        $actionsJson = new stdClass();
        $actionsJson->action_type = "SIGN";
        $actionsJson->recipient_name = $recipientName;
        $actionsJson->recipient_email = $recipientEmail;
        $actionsJson->verify_recipient = true;
        $actionsJson->verification_type="EMAIL";
        $actionsJson->signing_order = 0;
        
        $dataJson = new stdClass();
        $dataJson->actions = array($actionsJson);
        $request = new stdClass();
        $request->requests = $dataJson;
        $data = json_encode($request);
        $POST_DATA = array(
            'data' => $data
        );
        //used to make HTTP call to Sign API Endpoints
        $curl = curl_init("https://sign.zoho.com/api/v1/requests/".$requestId."/submit");
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Authorization:Zoho-oauthtoken '.$accessToken,
        ));
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
        $response = curl_exec($curl);
        echo $response;
        $jsonbody = json_decode($response); 
        if ($jsonbody->status == "success") {
            $created_request_id = $jsonbody->requests->request_id; 
            $status = $jsonbody->requests->request_status;
            echo $status;
        } 
        else //Error log
        {
            echo $jsonbody->message;
        }
        curl_close($curl);
    } else //Error log
    {
        echo $jsonbody->message;
    }

?>
Copiedconst fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');

async function CreateAndSubmit() {

    //replace the below data with the values you want to make this functioning
    var recipientName = "<recipient_name>";
    var recipientEmail = "<recipient_email>";
    var accessToken = "<Access Token>";
    var filePath = "<path of the file>"; //"/home/local/document_name.pdf"


    //Step 1 - Request Creation (Uploading document)
    let requestJson = {};
    requestJson['request_name'] = 'testDoc';
    requestJson['expiration_days'] = 10;
    requestJson['is_sequential'] = true;
    requestJson['notes'] = "Sign the document";

    let data = {};
    data['requests'] = requestJson;

    // let files = ['<File-Path>', '<File-Path>'];
    var payload = new FormData();
    if (fs.existsSync(files[0])) {
        let value = fs.createReadStream(files[0]);
        payload.append('file', value);
    } else {
        return 'unable to read file';
    }
    payload.append('data', JSON.stringify(data));

    let HEADERS = {};
    HEADERS['Authorization'] = 'Zoho-oauthtoken ' + accessToken;

    //used to make HTTP call to Sign API Endpoints
    let URL = 'https://sign.zoho.com/api/v1/requests';
    let method = 'POST';
    let requestOptions = {
        method: method,
        headers: HEADERS,
        body: payload
    };
    await fetch(URL, requestOptions)
        .then((_res) => {

            console.log(`Return code is ${_res.status}`);
            return _res.json().then((responseJson) => {
                var request_id = responseJson['requests'].request_id;

                let actionsJson = {};
                actionsJson['verify_recipient'] = false;
                actionsJson['recipient_name'] = recipientName;
                actionsJson['recipient_email'] = recipientEmail;
                actionsJson['action_type'] = "SIGN";
                actionsJson['signing_order'] = 0;

                let requestJson = {};
                requestJson['actions'] = new Array(actionsJson);

                let data = {};
                data['requests'] = requestJson;

                var payload = new FormData();
                payload.append('data', JSON.stringify(data));

                //used to make HTTP call to Sign API Endpoints
                let URL = 'https://sign.zoho.com/api/v1/requests/' + request_id + '/submit';
                let requestOptions = {
                    method: 'POST',
                    headers: HEADERS,
                    body: payload
                };

                return fetch(URL, requestOptions)
                    .then((_res) => {
                        console.log(`Return code is ${_res.status}`);
                        return _res.json().then((responseJson) => {
                            return responseJson['requests'];
                        });
                    })
                    .catch((error) => {
                        let errorResponse = {};
                        errorResponse['message'] = 'call failed to initiate'; //check internet connection or proper DC type
                        errorResponse['status'] = 'failure';
                        return errorResponse;
                    });
            });
        })
        .catch((error) => {
            let errorResponse = {};
            errorResponse['message'] = 'call failed to initiate'; //check internet connection or proper DC type
            errorResponse['status'] = 'failure';
            console.log(errorResponse);
        });

}
CreateAndSubmit();
Copiedvoid createAndSubmit()
{
	//replace the below data with the values you want to make this functioning
	recipientName = "<recipient_name>";
	recipientEmail = "<recipient_email>";
	//creating a request
	reqJson = Map();
	reqJson.put("request_name","testDoc");
	reqJson.put("expiration_days",10);
	reqJson.put("is_sequential",true);
	reqJson.put("notes","Sign the document");
	dataMap = Map();
	dataMap.put("requests",reqJson);
	// Fetch file from cloud
	 pdf_file = invokeurl
 [
 url :"https://www.zoho.com/sites/zweb/images/sign/documents/sample-social-media-policy-document.pdf"
 type :GET
 ];

	mp = Map();
	mp.put("data",dataMap);
	createDocResp = zoho.sign.createDocument(pdf_file,mp);
	if(createDocResp.get("status").equals("success"))
	{
		info "Document created successfully";
		info createDocResp;
		requestId = createDocResp.get("requests").get("request_id").toLong();
		reqJson = Map();
		actionJson = Map();
		actionJson.put("recipient_name",recipientName);
		actionJson.put("recipient_email",recipientEmail);
		actionJson.put("action_type","SIGN");
		actionJson.put("verify_recipient",false);
		actionJson.put("signing_order",0);
		actionsArray = List();
		actionsArray.add(actionJson);
		reqJson.put("actions",actionsArray);
		dataMap = Map();
		dataMap.put("requests",reqJson);
		mp = Map();
		mp.put("data",dataMap);
		submitDocResponse = zoho.sign.submitRequest(requestId,mp);
		info submitDocResponse;
		if(submitDocResponse.get("status").equals("success"))
		{
			info "Document sent out for signatures successfully";
			info submitDocResponse;
		}
	}
}