Skip to product menu
close
  • Recent Launches
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Recent Launches

New

Payroll software with automated tax payments and filing.

Try now
New

Robotic process automation software to automate high-volume, rule-based tasks.

Try for free
New

Low-code IoT platform and solutions for connected businesses.

Try now
New

Business formation service to launch and grow your businesses.

Try now
New

Privacy-friendly application analytics solution.

Try for free

Sales

 
CRM

Comprehensive CRM platform for customer-facing teams.

CRM
 
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
 
Forms

Build online forms for every business need.

Forms
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Sign

Digital signature app for businesses.

Sign
 
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

 
Social

All-in-one social media management software.

Social
 
Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
 
Forms

Build online forms for every business need.

Forms
 
Survey

Design surveys to reach and interact with your audience.

Survey
 
Sites

Online website builder with extensive customisation options.

Sites
 
PageSense

Website conversion optimization and personalisation platform.

PageSense
 
Backstage

End-to-end event management software.

Backstage
 
Webinar

Webinar platform for webcasting online webinars.

Webinar
 
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
 
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
 
Publish

Manage all your local business listings on a single platform.

Publish
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Sign

Digital signature app for businesses.

Sign
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
 
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
 
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce

 
Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

 
Desk

Helpdesk software to deliver great customer support.

Desk
 
Assist

Remote support and unattended remote access software.

Assist
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
FSM

End-to-end field service management platform for service businesses.

FSM
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

 
Books

Powerful accounting platform for growing businesses.

Books
 
FREE
Invoice

100% Free invoicing solution.

Invoice
 
Expense

Effortless expense reporting platform.

Expense
 
Inventory

Powerful stock management and inventory control software.

Inventory
 
Billing

End-to-end billing solution for your business.

Billing
 
Checkout

Collect payments online with custom branded pages.

Checkout
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Practice

Practice management software for accounting firms.

Practice
 
Sign

Digital signature app for businesses.

Sign
 
Commerce

eCommerce platform to manage and market your online store.

Commerce
 
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email and Collaboration

 
Mail

Secure email service for teams of all sizes.

Mail
 
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
 
Writer

Word processor for focused writing and discussions.

Writer
 
Sheet

Spreadsheet software for collaborative teams.

Sheet
 
Show

Create, edit, and share slides with a sleek presentation app.

Show
 
Notebook

Beautiful home for all your notes.

Notebook
 
Cliq

Stay in touch with teams no matter where you are.

Cliq
 
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
TeamInbox

Shared inboxes for teams.

TeamInbox
 
WorkDrive

Online file management for teams.

WorkDrive
 
Sign

Digital signature app for businesses.

Sign
 
Office Suite

Powerful collaborative work platform for teams.

Office Suite
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
 
Learn

Knowledge and learning management platform.

Learn
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
ToDo

Collaborative task management for individuals and teams.

ToDo
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
 
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

 
People

Organize, automate, and simplify your HR processes.

People
 
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
 
Expense

Effortless expense reporting platform.

Expense
 
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Shifts

Employee scheduling and time tracking app.

Shifts
 
Sign

Digital signature app for businesses.

Sign
 
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

 
Creator

Build custom apps to simplify business processes.

Creator
 
Directory

Workforce identity and access management solution for cloud businesses.

Directory
 
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
 
Vault

Online password manager for teams.

Vault
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
Assist

Remote support and unattended remote access software.

Assist
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA

BI and Analytics

 
Analytics

Modern self-service BI and analytics platform.

Analytics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
 
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT

Project Management

 
Projects

Manage, track, and collaborate on projects with teams.

Projects
 
Sprints

Planning and tracking tool for scrum teams.

Sprints
 
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo

Developer Platforms

 
Creator

Build custom apps to simplify business processes.

Creator
 
Flow

Automate business workflows by creating smart integrations.

Flow
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
 
NEW
Apptics

Application analytics for all apps.

Apptics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep

IoT

 
NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

 
CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
 
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
 
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
 
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
 
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
 
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
 
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho One
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Marketplace
Skip to main content

Serverless Functions - Using OAuth2

OAuth2

Functions can be made accessible through OAuth2 protocol. OAuth2 method allows you to share specific data with any application while keeping your usernames and passwords private, by having specific scopes which grant access to specfic data.

In order to make a function available through OAuth2 method, you need to first register your client with Zoho CRM. Please take a look here to know how to register your client application.

However, there are some key points that need to be noted:

  1. The scope for the client when using the HTTP GET Method should be:

    ZohoCRM.functions.execute.READ

  2. The scope for the client when using the HTTP POST Method should be:

    ZohoCRM.functions.execute.CREATE

Once the authentication is done, you can proceed with creating your function.

See also:

There are a lot of different situations where a function which is available as an API can be put to use. For instance, a function can be set to trigger whenever a certain limit has been crossed in statistical data of the performance of a company. This document is to give you a sample function which is triggered through external sources, where the function is provided as an API.

Sample function:

Scenario:

Say there is a requirement to get consent from customers and have them sign up for newsletters. This is to enable security and not infringe on their privacy.

You can have a button in View Page of a Contact record. The button can open a Widget, which pulls up a Subscription form(to be filled by your Agents). To create widgets, please refer our Widgets help.

Through the widget, the subscription form is submitted. Post which an email with the consent form is sent to the customer. After the customer accepts the consent form, the information about the contact is added to the MailChimp campaign list.

Required Applications:

  • MailChimp - for Newsletter
  • Google Drive - Consent Form

Requirements:

  1. Create Connections For MailChimp and Google Drive.
  2. Call MailChimp and Google Drive API in this Function.
  3. Turn the Function into an API.
  4. Create a Widget and invoke the Function within it.

Making the connections:

In order for the Function to make use of third-party applications and facilitate data transfer, you need to first set up a connection between Zoho CRM and the said third-party software. In this case, it would be MailChimp and Google Drive. Read more.

For MailChimp:

For Google Drive:

Create the Function:

The steps to create the function according to the requirement is split into 2 parts.

Part 1: Write the function code

Create a standalone function with the following code.

The Function Code is:

+

string subscribeNewsletter(string listId,string emailAddress,string extraDetails){
  mailChimpURL = "https://us18.api.mailchimp.com/3.0/";
  if(isNull(listId))
  {
    //Default List
    listId = "2a9a3690fd";
  }
  if(isNull(emailAddress))
  {
    return "Email Address cannot be null";
  }
  //Get all members
  membersList = invokeurl
  [
    url :mailChimpURL + "/lists/" + listId + "/members"
    type :GET
    parameters:""
    connection:<CONNECTION_LINKNAME>
  ];
  //Is Member already in List
  for each memberInfo in membersList.get("members")
  {
    if(emailAddress.equals(memberInfo.get("email_address")))
    {
      return "The member is already subscribed to Zoho Newsletter";
    }
  }
  //Get all Documents from Google Drive
  gdriveURL = "https://www.googleapis.com/drive/v2/files";
  fileList = invokeurl
  [
    url :gdriveURL
    type :GET
    parameters:""
    connection:<CONNECTION_LINKNAME>
  ];
  //Get Download URL of Consent Form
  webContentLink = null;
  for each fileInfo in fileList.get("items")
  {
    title = fileInfo.get("title");
    if(title.equals("Consent-Form.docx"))
    {
      webContentLink = fileInfo.get("webContentLink");
      break;
    }
  }
  if(isNull(webContentLink))
  {
    return "No Document Found on Drive. Docuemnt Name ::: Consent-Form.docx";
  }
  //Send Notification -
  name = "Guest";
  signature = "Zoho";
  if(!isNull(extraDetails))
  {
    if(extraDetails.contains("name"))
    {
      name = extraDetails.get("name");
    }
    if(extraDetails.contains("signature"))
    {
      signature = extraDetails.get("signature");
    }
  }
  sendmail
  [
    from :zoho.adminuserid
    to :emailAddress
    subject :"consent form"
    message :"Hi " + name + ",<expression></expression><div><br></div><div>Before subscribing to Zoho Newsletter, </div><br /><div>Please download the <br /><a target='_blank' href='" + webContentLink + "'>Consent Form</a> and mail it to newsletter@xyz.com</div><div><br></div><div><br></div><div>Regards,</div><div>" + signature + "<br></div>" ]   if(extraDetails.contains("mobile"))
  {
    sendsms
    [
      to :extraDetails.get("mobile")
      message:"Consent Form has been sent to your mail id :- " + emailAddress
    ];
  }
  return "Consent form sent successfully"; }

 

Note:

  • The entire request body will not be available inside the Function. It needs to be sent or received inside the arguments.

Configure an argument which contains the entire request body.

In the function given above, you can see that we have 'extraDetails' as one of our Function argument. It is used to get name and signature from the user. This will be helpful when there is no way of knowing the number of arguments that will be passed to your Function.

Since there is no way of knowing the number of arguments present in it, you can have the function contain the entire request body within a single argument, i'e "extraDetails" in this case.

Note:

  • Value of 'listId' will be '2a9a3690fd'(in case of null).
  • 'emailAddress' is mandatory.
  • 'extraDetails' argument is provided to pass extra info, the one which contains the entire request body.
  • 'listId', 'emailAddress' are of type STRING.
  • 'extraDetails' is of type STRING and we are passing JSON in 'extraDetails'.

Part 2: Make the function available as an API

Once the function has been created, tested and saved, you can proceed to turn the function into an API.

  1. Go to Setup > Developer Hub > Functions.
  2. Click the Settings icon for the corresponding function which needs to be made an API.
  3. Click REST API.
  4. Enable OAuth2 slider.
  5. Click Save.

Calling the function inside Widgets

Now comes the actual working part. Since the function has been turned into an API call, you can use the API code for the function in any widget, app or software and set it up to trigger based on your requirement.

Use the following HTML code (Consent Form of the Newsletter), to create a Widget. To learn how to create widgets, please click here.

HTML Code:

<h2>XYZ Newsletter</h2>
<div class="container">
<h2<Subscribe to our Newsletter</h2>
</div>
<div class="container" style="background-color:white">
<input type="text" id="name" placeholder="Name" name="name" required>
<input type="text" placeholder="Email address" name="mail" required id="email">
<label>
<input type="checkbox" checked="checked" name="subscribe">Daily Newsletter
</label>
</div>
<div class="container">
<input type="submit" value="Subscribe" id="subscribeButton">
</div>
<span id="res1">Click on the above button to Subscribe</span>

Script(Javascript):

<script type="text/javascript">

$("#subscribeButton").click(function() {
  var extraDetails = {};
  extraDetails.name = $("#name").val();
  extraDetails.signature = "XYZ";
  var arguments = {};
  arguments.extraDetails = extraDetails;
  arguments.emailAddress = $("#email").val();
  var data = {
      "arguments": JSON.stringify(arguments),
  }

  ZOHO.embeddedApp.init()
    .then(function() {

      ZOHO.CRM.FUNCTIONS.execute("subscribenewsletter", data)
        .then(function(resp) {
        $('#res1').text(JSON.stringify(resp));
        }).catch(function(resp) {
          $('#res1').text(JSON.stringify(resp));
        })
    });
});

Note:

  • The above script only works for widgets placed inside the CRM.
  • To learn more about the Integration Tasks for Functions, click here.

The Outcome:

Subscribing to the Newsletter:

Getting the subscription mail:

Once the Consent form is sent back to the mailer, the newsletter subscription will be enabled.

Disadvantages of not using Serverless functions:

The user has to manually:

  • Register the application on MailChimp and Google Drive.
  • Code to handle OAuth2 flow.
  • Call Mailchimp API's to verify the user availability.
  • Call Google Drive API, to retrieve document URL.
  • Code to send Email and SMS to Customer.

As you can see from the above steps, there are a lot of steps involved, which requires you to manually write codes for the widget as well as the functionality of the widget. However, this method is time consuming and requires a ton of manual effort. You can avoid them by having the function as a serverless one.