What?
A separate article as a follow-on from my previous article in this series Zoho Survey & Zoho Analytics: Query to generate individual responses and grouped pages which may have grown a little but just wanted to record how to receive a Zoho Survey response in a Zoho CRM REST API function.

Why?
As above, didn't want to overload a single article with all the answers of one development but this one may be referred to separately. I want a Zoho Survey when submitted to be parsed by a Zoho CRM REST API function.

How?
First, I'll go through the steps of setting up the Zoho CRM function, we'll convert it to a REST API function which will give us a URL and then we'll configure the Zoho Survey to trigger a webhook when submitted.

Pre-Amble
Just need a few fields on the CRM contact record to store the survey metadata
  1. Login to ZohoCRM with permissions to edit modules
  2. Go to Setup > Modules and Fields > Contacts > Layout > Standard
  3. Add the section: "Latest Survey"
  4. Add to it the fields "Response ID", "Survey ID", "Scheduled Report Generation Time"
  5. Save and close

the CRM function
You should know how to set up a CRM function as a REST API function but here goes a quick recap:
  1. Login to ZohoCRM as a user who has permission to create functions
  2. Create a CRM function, I'm calling mine "Fn - Submit Suspect Survey - Webhook" with internal name as fn_SubmitSuspectSurvey_Webhook and the parameter is a string called crmAPIRequest
  3. Give it the following code:
    string standalone.fn_SubmitSuspectSurvey_Webhook(String crmAPIRequest)
    {
    /* *******************************************************************************
    	Function:       string standalone.fn_SubmitSuspectSurvey_Webhook(String crmAPIRequest)
    	Label:          Fn - Submit Suspect Survey - Webhook
    	Trigger:        Webhook when a suvey is submitted in Zoho Survey
    	Purpose:		Push the calculated score and results from Analytics into the corresponding Zoho CRM record.
    	Inputs:         String crmAPIRequest
    	Outputs:        -
    
    	Date Created:   2025-09-19 (Joel Lipman)
    					- Initial release
    					- Identifies a survey by email
    	Date Modified:	2025-10-06 (Joel Lipman)
    					- Clients wants a public URL for Survey: Need this webhook to create contact/account on-the-fly if needed.
    
    	More Information:
    					Within Zoho Surveys, configure the webhook to return the Response ID, Email, and Survey ID:
    					1. Login to Zoho Surveys
    					2. Click on the Survey > Builder > Hub > Triggers > Webhook > Manage
    					3. Post URL is the REST API URL of the ZohoCRM function (this function)
    					4. Set Request Body to JSON with name 'Survey' and within specify Response ID, Email, and Survey ID mapping as appropriate.
    					5. Click on 'Save' button at the bottom of the page
    					
    					CAVEAT: If you have multiple contacts in your CRM with the same email address, then you're stuffed.
    
    	******************************************************************************* */
    	v_WebhookBody = ifnull(crmAPIRequest.toMap().get("body"),"");
    	v_WebhookBodyDecode = zoho.encryption.urlDecode(v_WebhookBody);
    	v_WebhookBodyString = v_WebhookBodyDecode.getSuffix("Survey=");
    	m_SurveyBody = v_WebhookBodyString.toMap();
    	//
    	// find contact by email
    	v_CrmContactID = "";
    	l_SearchContacts = zoho.crm.searchRecords("Contacts","Email:equals:" + m_SurveyBody.get("Email"));
    	for each  m_ContactResult in l_SearchContacts
    	{
    		//
    		// if found then simply update the contact
    		if(!isNull(m_ContactResult.get("id")))
    		{
    			v_CrmContactID = m_ContactResult.get("id");
    			m_UpdateContact = Map();
    			m_UpdateContact.put("Response_ID",m_SurveyBody.get("Response_ID"));
    			m_UpdateContact.put("Survey_ID",m_SurveyBody.get("Survey_ID"));
    			m_UpdateContact.put("Scheduled_Report_Generation_Time",zoho.currenttime.addHour(1).toString("yyyy-MM-dd'T'HH:mm:ss","Europe/London"));
    			r_UpdateContact = zoho.crm.updateRecord("Contacts",m_ContactResult.get("id"),m_UpdateContact);
    			info "Updating CRM Contact: " + r_UpdateContact;
    		}
    	}
    	if(v_CrmContactID == "")
    	{
    		//
    		// create an account/company record to associate the contact to
    		v_CrmAccountID = "";
    		if(!isNull(m_SurveyBody.get("Company")))
    		{
    			m_CreateAccount = Map();
    			m_CreateAccount.put("Account_Name", m_SurveyBody.get("Company"));
    			m_CreateAccount.put("Number_of_Employees", m_SurveyBody.get("Number_of_Employees"));
    			m_CreateAccount.put("Turnover", m_SurveyBody.get("Last_Years_Turnover"));
    			r_CreateAccount = zoho.crm.createRecord("Accounts", m_CreateAccount);
    			info "Creating CRM Account: " + r_CreateAccount;
    			if(!isNull(r_CreateAccount.get("id")))
    			{
    				v_CrmAccountID = r_CreateAccount.get("id");
    			}
    		}
    		// create this contact as they filled in the survey without us sending it to them
    		m_CreateContact = Map();
    		m_CreateContact.put("First_Name", m_SurveyBody.get("First_Name"));
    		m_CreateContact.put("Last_Name", m_SurveyBody.get("Last_Name"));
    		m_CreateContact.put("Phone", m_SurveyBody.get("Phone"));
    		m_CreateContact.put("Email", m_SurveyBody.get("Email"));
    		m_CreateContact.put("Title", m_SurveyBody.get("Job_Title"));
    		if(v_CrmAccountID != "")
    		{
    			m_CreateContact.put("Account_Name", v_CrmAccountID);
    		}
    		m_CreateContact.put("Response_ID",m_SurveyBody.get("Response_ID"));
    		m_CreateContact.put("Survey_ID",m_SurveyBody.get("Survey_ID"));
    		m_CreateContact.put("Scheduled_Report_Generation_Time",zoho.currenttime.addHour(1).toString("yyyy-MM-dd'T'HH:mm:ss","Europe/London"));	
    		r_CreateContact = zoho.crm.createRecord("Contacts", m_CreateContact);
    		info "Creating CRM Contact: " + r_CreateContact;
    	}
    	/* OPTIONAL: Send yourself an email
    		sendmail
    		[
    			from :zoho.adminuserid
    			to :"me@mycompany.com"
    			subject :"TEST: Survey has been submitted"
    			message :crmAPIRequest
    		]
    	*/
    	//
    	// build response to Zoho Survey (hard-coded a ok)
    	m_ResponseHeader = Map();
    	m_ResponseHeader.put("status_code",200);
    	return {"crmAPIResponse":m_ResponseHeader};
    }
  4. Save the function, hover over it and select "REST API", enable both options and copy the URL for the REST API

Configuring Zoho Survey
  1. Login to Zoho Surveys
  2. Click on the Survey > Builder > Hub > Triggers > Webhook > Manage
  3. Post URL is the REST API URL of the ZohoCRM function (this function)
  4. Set Request Body to JSON with name 'Survey' and within specify Response ID, Email, and Survey ID mapping as appropriate.
  5. Click on 'Save' button at the bottom of the page

Source(s):