For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 392 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

ZohoFlow & ZohoSign: Retrieve a Zoho Sign document request and add attachments to CRM record

What?
This is an article describing a custom function built into Zoho Flow that will accept as parameter the document_id and request_id. It then retrieves the Deal Reference (entered by an office signee) on the ZohoSign document and searches for the relevant Deal record in CRM.

Why?
A client wants that when this field is entered and the document signed and returned, it attached the signed document to the Deal record.

How?
The following is the process from registering the app to call on the full API (grant code > refresh token > access token) and then the code to attach the document to the CRM record.

STEP 1: REGISTER A NEW CLIENT
First, you need to register your application with Zoho’s developer console to get your Client ID and Client Secret. (Login as the client super admin or ascentcloud admin account)
  1. Log in to https://accounts.zoho.com/developerconsole
  2. Click on Add Client ID
  3. Select "Self Client"
  4. Provide the details and register your application
Upon successful authentication, you will be provided with Client ID and Client Secret. Do not share the Client ID and Client Secret with anyone.


STEP 2: GENERATE A GRANT CODE
  1. On the above screen (Zoho API Console - Applications @ https://api-console.zoho.com/)
  2. Select your "Self Client"
  3. Enter in the applicable Scope(s): eg. ZohoSign.documents.ALL,ZohoSign.templates.ALL (possibly incl. ZohoSign.account.ALL)
  4. Click on "Create"
You now have about 3 minutes to do the following step (repeat this step if you fail)


STEP 3: GENERATE A REFRESH TOKEN
  1. For the following, browse to Zoho Sign, login as the customer, click on Settings > API Tokens > then API token - deployment > Get Started
  2. Fill out the client ID and client secret along with the Grant Code
  3. Click the button and you will get a refresh token which you can copy for the next step.


STEP 4: THE REST
A Zoho Flow would submit the request ID and document ID as part of a map to the following function:

copyraw
void fn_SignDataAndAttach(int v_RequestId, int v_DocumentId)
{
	//
	// TLD as com or eu depending on whether you access zoho.com or zoho.eu
	v_TLD = "com";
	//
	// enter client ID, secret and refresh token as noted from above steps (the below are sample ones and will not work)
	v_ClientID = "1000.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234"; 
	v_ClientSecret = "aaaabbbbccccddddeeeeffff111122223333444455"; 
	v_RefreshToken = "1000.aaaabbbbccccddddeeeeffff11112222.33334444555566667777888899990000";
	//
	// build URL to query
	l_Params = List();
	l_Params.add("refresh_token="+v_RefreshToken);
	l_Params.add("client_id="+v_ClientID);
	l_Params.add("client_secret="+v_ClientSecret);
	l_Params.add("redirect_uri=https%3A%2F%2Fsign.zoho." + v_TLD);
	l_Params.add("grant_type=refresh_token");
	v_Url = "https://accounts.zoho."+v_TLD+"/oauth/v2/token?" + l_Params.toString("&");
	r_AccessToken = invokeUrl
    [
    	url: v_Url
    	type: POST
    ];
	//
	// output
	v_AccessToken = ifnull(r_AccessToken.get("access_token"), "");
	//
	// use the access token to query requests
	m_Header = Map();
	m_Header.put("Authorization","Zoho-oauthtoken " + v_AccessToken);
	v_Url = "https://sign.zoho.com/api/v1/requests/" + v_RequestId;
	r_RequestDetails = invokeurl
	[
		url :v_Url
		type :GET
		headers:m_Header
	];
	//
	// retrieve the value of field "Deal_Ref" from the ZohoSign Document Request
	v_DealRef = "";
	if(!isnull(r_RequestDetails.get("requests")))
	{
		if(!isnull(r_RequestDetails.get("requests").get("actions")))
		{
			l_Actions = r_RequestDetails.get("requests").get("actions");
			for each  r_Action in l_Actions
			{
				if(!isnull(r_Action.get("fields")))
				{
					for each  r_Field in r_Action.get("fields")
					{
						if(r_Field.get("field_name") == "Deal_Ref")
						{
							v_DealRef = r_Field.get("field_value");
						}
					}
				}
			}
		}
	}
	//
	// Search ZohoCRM for the Deal with that Deal Ref
	v_DealID = 0;
	if(v_DealRef != "")
	{
		l_SearchResults = zoho.crm.searchRecords("Deals","(Reference_ID:equals:" + v_DealRef + ")",1,200,{"converted":"both","approved":"both"});
		for each  r_Result in l_SearchResults
		{
			if(!isnull(r_Result.get("id")))
			{
				v_DealID = r_Result.get("id").toLong();
			}
		}
	}
	//
	// if Deal ID is not zero, then it was found!
	if(v_DealID != 0)
	{
		r_DealDetails = zoho.crm.getRecordById("Deals",v_DealID,{"converted":"both","approved":"both"});
		//
		// do stuff here such as updating the deal if required
		m_UpdateDeal = Map();
		r_UpdateDeal = zoho.crm.updateRecord("Deals", v_DealID, m_UpdateDeal);
	}
	//
	// now we have deal ID, retrieve the request documents
	if(!isnull(r_RequestDetails.get("requests")))
	{
		if(!isnull(r_RequestDetails.get("requests").get("document_ids")))
		{
			l_Documents = r_RequestDetails.get("requests").get("document_ids");
			for each r_Document in l_Documents
            {
				v_DocumentName = r_Document.get("document_name");
				v_ThisDocumentId = r_Document.get("document_id");
				if(v_ThisDocumentId == v_DocumentId)
				{
					r_File = invokeurl
					[
						url :"https://sign.zoho."+v_TLD+"/api/v1/requests/" + v_RequestId + "/documents/" + v_DocumentId + "/pdf"
						type :GET
						headers:m_Header
					];
					// if this doesn't work, enable one of the following 2 lines
					//r_File.setParamName("attachment");
					//r_File.setParamName("file");
					r_File.setFileName(v_DocumentName);
					r_Attach = zoho.crm.attachFile("Deals",v_DealID,r_File);
					info r_Attach;
					//
					// to send this as an email as well
					sendmail
					[
						from :zoho.adminuserid
						to :"This email address is being protected from spambots. You need JavaScript enabled to view it."
						subject :"ZohoSign Test - Request: " + v_RequestId + " - Document: " + v_DocumentId
						message :"Please find attached your requested document(s)"
						Attachments :file:r_File
					];
				}
            } 
		}
	}
}
  1.  void fn_SignDataAndAttach(int v_RequestId, int v_DocumentId) 
  2.  { 
  3.      // 
  4.      // TLD as com or eu depending on whether you access zoho.com or zoho.eu 
  5.      v_TLD = "com"
  6.      // 
  7.      // enter client ID, secret and refresh token as noted from above steps (the below are sample ones and will not work) 
  8.      v_ClientID = "1000.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234"
  9.      v_ClientSecret = "aaaabbbbccccddddeeeeffff111122223333444455"
  10.      v_RefreshToken = "1000.aaaabbbbccccddddeeeeffff11112222.33334444555566667777888899990000"
  11.      // 
  12.      // build URL to query 
  13.      l_Params = List()
  14.      l_Params.add("refresh_token="+v_RefreshToken)
  15.      l_Params.add("client_id="+v_ClientID)
  16.      l_Params.add("client_secret="+v_ClientSecret)
  17.      l_Params.add("redirect_uri=https%3A%2F%2Fsign.zoho." + v_TLD)
  18.      l_Params.add("grant_type=refresh_token")
  19.      v_Url = "https://accounts.zoho."+v_TLD+"/oauth/v2/token?" + l_Params.toString("&")
  20.      r_AccessToken = invokeUrl 
  21.      [ 
  22.          url: v_Url 
  23.          type: POST 
  24.      ]
  25.      // 
  26.      // output 
  27.      v_AccessToken = ifnull(r_AccessToken.get("access_token"), "")
  28.      // 
  29.      // use the access token to query requests 
  30.      m_Header = Map()
  31.      m_Header.put("Authorization","Zoho-oauthtoken " + v_AccessToken)
  32.      v_Url = "https://sign.zoho.com/api/v1/requests/" + v_RequestId; 
  33.      r_RequestDetails = invokeUrl 
  34.      [ 
  35.          url :v_Url 
  36.          type :GET 
  37.          headers:m_Header 
  38.      ]
  39.      // 
  40.      // retrieve the value of field "Deal_Ref" from the ZohoSign Document Request 
  41.      v_DealRef = ""
  42.      if(!isnull(r_RequestDetails.get("requests"))) 
  43.      { 
  44.          if(!isnull(r_RequestDetails.get("requests").get("actions"))) 
  45.          { 
  46.              l_Actions = r_RequestDetails.get("requests").get("actions")
  47.              for each  r_Action in l_Actions 
  48.              { 
  49.                  if(!isnull(r_Action.get("fields"))) 
  50.                  { 
  51.                      for each  r_Field in r_Action.get("fields") 
  52.                      { 
  53.                          if(r_Field.get("field_name") == "Deal_Ref") 
  54.                          { 
  55.                              v_DealRef = r_Field.get("field_value")
  56.                          } 
  57.                      } 
  58.                  } 
  59.              } 
  60.          } 
  61.      } 
  62.      // 
  63.      // Search ZohoCRM for the Deal with that Deal Ref 
  64.      v_DealID = 0
  65.      if(v_DealRef != "") 
  66.      { 
  67.          l_SearchResults = zoho.crm.searchRecords("Deals","(Reference_ID:equals:" + v_DealRef + ")",1,200,{"converted":"both","approved":"both"})
  68.          for each  r_Result in l_SearchResults 
  69.          { 
  70.              if(!isnull(r_Result.get("id"))) 
  71.              { 
  72.                  v_DealID = r_Result.get("id").toLong()
  73.              } 
  74.          } 
  75.      } 
  76.      // 
  77.      // if Deal ID is not zero, then it was found! 
  78.      if(v_DealID != 0) 
  79.      { 
  80.          r_DealDetails = zoho.crm.getRecordById("Deals",v_DealID,{"converted":"both","approved":"both"})
  81.          // 
  82.          // do stuff here such as updating the deal if required 
  83.          m_UpdateDeal = Map()
  84.          r_UpdateDeal = zoho.crm.updateRecord("Deals", v_DealID, m_UpdateDeal)
  85.      } 
  86.      // 
  87.      // now we have deal ID, retrieve the request documents 
  88.      if(!isnull(r_RequestDetails.get("requests"))) 
  89.      { 
  90.          if(!isnull(r_RequestDetails.get("requests").get("document_ids"))) 
  91.          { 
  92.              l_Documents = r_RequestDetails.get("requests").get("document_ids")
  93.              for each r_Document in l_Documents 
  94.              { 
  95.                  v_DocumentName = r_Document.get("document_name")
  96.                  v_ThisDocumentId = r_Document.get("document_id")
  97.                  if(v_ThisDocumentId == v_DocumentId) 
  98.                  { 
  99.                      r_File = invokeUrl 
  100.                      [ 
  101.                          url :"https://sign.zoho."+v_TLD+"/api/v1/requests/" + v_RequestId + "/documents/" + v_DocumentId + "/pdf" 
  102.                          type :GET 
  103.                          headers:m_Header 
  104.                      ]
  105.                      // if this doesn't work, enable one of the following 2 lines 
  106.                      //r_File.setParamName("attachment")
  107.                      //r_File.setParamName("file")
  108.                      r_File.setFileName(v_DocumentName)
  109.                      r_Attach = zoho.crm.attachFile("Deals",v_DealID,r_File)
  110.                      info r_Attach; 
  111.                      // 
  112.                      // to send this as an email as well 
  113.                      sendmail 
  114.                      [ 
  115.                          from :zoho.adminuserid 
  116.                          to :"This email address is being protected from spambots. You need JavaScript enabled to view it." 
  117.                          subject :"ZohoSign Test - Request: " + v_RequestId + " - Document: " + v_DocumentId 
  118.                          message :"Please find attached your requested document(s)" 
  119.                          Attachments :file:r_File 
  120.                      ]
  121.                  } 
  122.              } 
  123.          } 
  124.      } 
  125.  } 
Category: Zoho :: Article: 822

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 bc1qjtp4l4ra452wzvuk9a45yfj82zkahsyy2z379y
© 2022 Joel Lipman .com. All Rights Reserved.