For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

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: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience 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 bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.