API Trigger Custom Function

API Trigger Custom Function

AlertNote: The API Trigger Custom Function feature is currently in its beta stage with further enhancements planned in the product roadmap. Contact support@zohoiot.com to enable it for your application and for more details .
The API triggered custom function in Zoho IoT lets external or third-party applications execute a custom function through REST APIs. When triggered, the function runs immediately and performs whatever logic you’ve configured.

Inside the custom function, you can handle aggregation of device metrics, comparisons over time, fetching multiple data points, computing derived values, or combining readings across devices. The custom function processes everything and returns only the result required and can be invoked through webhooks.

API Trigger custom functions must be written using the Deluge scripting language.

This document explains how to create a API trigger custom function, how to access its REST API and provides an example code demonstrating its use.

Creating an API Trigger Custom Function

To create an API trigger custom function,
  1. Click Add Custom Function.



  2. Select API Trigger in the Category field.



  3. Provide the required values in the appropriate fields.

    Example -
    Language : Deluge
    Display Name: Fuel Consumption On Demand (Provide a name of your choice)
    Function Name: fuel_consumption_on_demand (Provide a name of your choice)
    Description: An API trigger custom function that aggregates the fuel consumed by two diesel generators from the start of the current month up to the present time.



  4. Click Save. This will open the Code Editor.



  5. Provide the required code.



  6. Click Save and Close.


The API trigger custom function is created. You can now use the RESP API of the custom function to trigger it from an external application.

Obtaining the REST API of the custom function

To obtain the REST API of a custom function,
  1. Hover over the required API Trigger custom function and Select the ellipsis icon that appear. For this illustration, Fuel Consumption On Demand is selected. 



  2. Select View REST API from the context menu.



  3. Hover over the REST API and copy it. 


You can now use this REST API to trigger the custom function.

API Trigger Custom Function Code Example

Below is an example of using a custom function to simplify third party integration. When a Zoho Creator based application requires fuel consumption data from multiple diesel generators, it invokes an API triggered custom function in the Zoho IoT application through a REST call. The function aggregates fuel usage across the relevant generators, processes the required calculations, and returns the consolidated results, allowing the Zoho Creator application to keep its webhook implementation minimal and free of complex processing.

url1 = "https://app12345akyrw.zohoiot.com/iot/v1/datapoints/data?datapoint_name=Fuel%20Consumed& source=DG001&aggregation=sum&time_grouping=month&period=thismonth";
response1 = invokeurl
[
url :url1
type :GET
connection:"datapointcirrus"
];
url2 = "https://app12345akyrw.zohoiot.com/iot/v1/datapoints/data?datapoint_name=Fuel%20Consumed& source=DG002&aggregation=sum&time_grouping=month&period=thismonth";
response2 = invokeurl
[
url :url2
type :GET
connection:"datapoint-iot"
];
info "RESPONSE:: " + response1 + response2;
fuel_consumed_dg1 = response1.get("Fuel Consumed").get(0).get(1);
fuel_consumed_dg2 = response2.get("Fuel Consumed").get(0).get(1);
fuel_consumed_dg_all = fuel_consumed_dg1 + fuel_consumed_dg2;
url3 = "https://www.zohoapis.com/creator/v2.1/data/user.useredu/dg-monitiring/form/Fuel_Data";
payload = Map();
dataList = List();
recordMap = Map();
recordMap.put("Fuel_Consumed",fuel_consumed_dg_all);
dataList.add(recordMap);
payload.put("data",dataList);
response3 = invokeurl
[
url :url3
type :POST
parameters:payload.toString()
connection:"creator-iot-post"
];


      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsEnterpriseOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceAccessible Forms
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit

                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic Forms
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsFormstack alternativeEncrypted Forms

                              Wufoo alternativeSecure Forms

                              TypeformWCAG


                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now




                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media


                                                                  • Desk Community Learning Series


                                                                  • Digest


                                                                  • Functions


                                                                  • Meetups


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner


                                                                  • Word of the Day


                                                                  • Ask the Experts


                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now








                                                                                                                            • Related Articles

                                                                                                                            • Understanding Custom Functions

                                                                                                                              Custom functions in Zoho IoT allow you to extend the platform's capabilities. These functions are written using various programming languages and are easy to construct. With custom functions, users can move beyond the default offerings of the ...
                                                                                                                            • Adding and managing custom functions

                                                                                                                              Adding Custom Functions A custom function can be added for one of the below listed categories, each corresponding to a specific feature in the application. Once created, the custom function becomes available for the feature in the selected ...
                                                                                                                            • Workflow Custom Function

                                                                                                                              When a Workflow Rule is configured in Zoho IoT, you define the condition that determines when the rule should run. As part of this configuration, you can assign a custom function that executes whenever the workflow rule is triggered. Each time the ...
                                                                                                                            • Notification Profile Custom Function

                                                                                                                              In Zoho IoT, notification profiles are configurations that determine how and when notification related actions should be executed in response to alarms - either when a new alarm is created or when its status changes (severity, acknowledgement, ...
                                                                                                                            • Alarm Rule Custom Function

                                                                                                                              When an Alarm Rule is configured in Zoho IoT, you define the condition under which the alarm should be raised. As part of this configuration, you can specify a custom function to run as the end action. Each time the alarm is triggered, the associated ...
                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources