How to set up a callback function in CRM to add Zoho Sign document details that is triggered by the Zoho Sign webhook?

How to set up a callback function in CRM to add Zoho Sign document details that is triggered by the Zoho Sign webhook?

ScenarioWithin a Custom module in ZohoCRM, I have set up an automation to send documents to Zoho Sign. Each time I want to view the documents, I need to view them at Zoho Sign. Can I set up a callback function in CRM to add Zoho Sign document details that is triggered by the Zoho Sign webhook?

  1. Custom Modules allow the user to send customized attachments (completion certificate, signed copy of the document) as per the user's requirement.
  2. When you have sent documents to sign using Automation/Workflows. These docs will only be available in Zoho Sign but will not be updated back in crm. Once you have setup this code, this will help you to create/update Zoho Sign docs entry in CRM.
  3. You can view the set up function by clicking here.
Paste the code that is given below. 
Note: In this example code, the Custom Module name is "Commercial_Terms". Use the replaced module name when using the code.
  1. crmAPIRequestMap = crmAPIRequest.toMap();
  2. //crmAPIRequest is the parameter passed to this function
  3. request_body = crmAPIRequestMap.get("body");
  4. info request_body;
  5. requestMap = request_body.toMap();
  6. response = Map();
  7. response.put("status_code",200);
  8. response.put("Content-Type","application/json");
  9. hasRequests = requestMap.containKey("requests");
  10. if(requestMap.containKey("requests"))
  11. {
  12. requestStr = requestMap.get("requests");
  13. requestObj = requestStr.toMap();
  14. notificationObj = requestMap.get("notifications").toMap();
  15. response.put("body",{"what we got":requestObj});
  16. if(requestObj.containKey("request_status"))
  17. {
  18. reqStatus = requestObj.get("request_status");
  19. requestId = requestObj.get("request_id");
  20. response.put("body",{"request_id":requestId});
  21. info "Record found";
  22. document_ids = requestObj.get("document_ids");
  23. records = zoho.crm.searchRecords("Commercial_Terms","(Sign_Request_Id:equals:" + requestId + ")");
  24. if(records.size() > 0 && reqStatus.equals("completed") && notificationObj.get("operation_type").equals("RequestCompleted"))
  25. {
  26. info "Record found";
  27. leadid = records.get(0).get("id");
  28. for each  document in document_ids
  29. {
  30. document_id = document.get("document_id");
  31. //Signed Document Download
  32. fileResponse = invokeurl
  33. [
  34. url :"https://sign.zoho.com/api/v1/requests/" + requestId + "/documents/" + document_id + "/pdf"
  35. type :GET
  36. connection:"Zoho Sign"
  37. ];
  38. docName = fileResponse.getFileName();
  39. fileResponse.setFileName(docName);
  40. zoho.crm.attachFile("Commercial_Terms",leadid,fileResponse);
  41. }
  42. //Completion Certificate Download
  43. fileResponse2 = invokeurl
  44. [
  45. url :"https://sign.zoho.com/api/v1/requests/" + requestId + "/completioncertificate"
  46. type :GET
  47. connection:"Zoho Sign"
  48. ];
  49. // Attaching the documents to the Custom Module
  50. zoho.crm.attachFile("Commercial_Terms",leadid,fileResponse2);
  51. response.put("body",{"attached to record":leadid});
  52. }
  53. }
  54. else
  55. {
  56. response.put("body",{"no request status":requestObj});
  57. }
  58. }
  59. else
  60. {
  61. info "Error";
  62. response.put("body",{"error":"No requests key"});
  63. }
  64. return {"crmAPIResponse":response};