Sending Details to ERP Service

Sending Details to ERP Service


Let us consider a scenario where a customer is monitoring energy consumption in a building by implementing the Zoho IoT's Energy monitoring solution. At the start of every month, the customer wants to calculate the energy consumed in the previous month and send it to the ERP system used by the customer for billing purposes.

This implementation is achieved using the functionality Schedules and Custom Function action as the requirement is to perform the same operation every month.


Prerequisites

First, ensure that the following prerequisites including the necessary licenses, permissions, setups, and configurations are in place.
  1. Have a valid Zoho IoT account with the required licenses and authenticated ERP credentials.
  2. Ensure the user has permissions for Schedules and Custom Functions.
  3. A Zoho IoT application must be set up to monitor and manage building energy consumption.
  4. Configure an energy meter instance (e.g., Energy Meter 1) as the parent meter to consolidate data from all building assets.

Implementation   

The following outlines the high-level steps involved in the implementation.
  1. Configuring Connections - To execute the APIs call inside the custom function when it is triggered i.e. every month, configure connections as authentication for respective APIs.
  2. Creating a Schedule - To execute at start of every month and execute the associated custom function.
  3. Creating a Custom Function - To include the business logic to get the needed data and send to the ERP application.

Procedure 

The following provides a step-by-step procedure of the implementation.

 

Step 1: Configure Connections 

We will be creating two connections in the step.
  1. Connection named IoT Connection using Zoho IoT Service (if available) or Custom Service to authenticate when calling the Zoho IoT API.
  2. Connection named ERP Connection using Custom Service to authenticate the ERP APIs.

To create the Zoho IoT connection,
  1. Access the End Application. Click on the Setup icon.
  2. Click Connections under the INTEGRATIONS section.

    The below page is displayed if there are no connections configured.


Image: Sample connections home page

    Else,
    The available connections (if any) are displayed on the right.


Image: Sample connections home page with configured connections

3. Click Create Connection button at the center of the screen or at the top right corner of the screen.
NotesNote: As the scope ZohoIOT.settings.cirrus.data.READ scope that is used to fetch data from the application is not available in any default service, you need to create a Custom Service connection. Refer to the Creating Custom Services document for complete details.

4. Select the Custom Services tab.



5. In the Custom Service tab, click Create New Service.



      To create a custom connection for this implementation:
    1. Provide the service details for the connection as in the screenshot below.
    2. The Oauth details such as Client ID and Client Secret can be obtained by registering the client (application).
    3. Provide the scope as ZohoIOT.settings.cirrus.data.READ. The ZohoIOT.settings.cirrus.data.READ scope is used to fetch data from the application.
    4. Click Create Service



      Image: Sample connections configuration screen

5. The Service is created. Click Create Connection in the resultant page. 



6. Provide the Connection Name and Connection Link Name
7. Click Create and Connect.



Image: Sample connections configuration screen

9. Click Connect.


Image: Connections Connect screen

10. Once connected, the below screen will be displayed with the sample code.
11. The entries from the highlighted code below is used in the deluge custom function code.
Alert
Important: You will be using the url, type, parameter, and connection entries when writing your logic in the custom function.



Image: Deluge code


Similarly, create a second connection ERP Connection using Custom Service for accessing the ERP service securely using OAuth 2.0 or API Key. Refer to the Creating Custom Services document for complete details.

To create the ERP Service connection,

1. Select the Custom Services tab.



5. In the Custom Services tab, click Create New Service.



      To create a custom connection for this implementation:
    1. Provide the service details as in the screenshot.
    2. Click Create Service. The service ERP_Service is created. 
      


Image: Sample Custom Service creation screen for ERP Connection

                    3. In the resultant screen, click Create Connection to create a connection using the ERP_Service.




4. Provide the Connection Name and Connection Link Name.
5. Click Create and Connect. This connection allows Zoho IoT to send or receive data from the ERP system without re-entering credentials each time.



Image: Sample Custom Service creation screen

5. The Sample codes are displayed in the resultant connection screen. The highlighted code below is used in the custom function code.

Alert
Important: You need to modify the url, type, and parameter entries with your values when writing your logic in the custom function.


.
Image: Connection screen with deluge script


Step 2:  Create a Schedule

Configure a schedule to run at the start of every month. 

To create a new schedule,
  1. Access the End Application.
  2. Click on the Setup icon.
  3. Click Schedules under the AUTOMATION section. The schedules available (if any) are displayed in the right.



    Image: Schedule home page

  4. Click the Add Schedule button in the top right corner. The New Schedule addition form is displayed.
  5. Provide the name for the schedule, and provide the required details.


    Image: Sample Schedule configuration screen

  6. In Configuring Actions, click Add Action
  7. Select Custom Function. The available custom functions (if any) are displayed.
  8. Select the custom function from here, and it will be associated to the schedule.
    Else,
    If you have not yet created the custom function, Click the Custom Function button to create a new custom function for the schedule.

Step 3: Create a Custom Function

In the custom function's editor, provide code to implement the business logic to:
  1. Connect to the IoT application.
  2. Retrieve the datapoints for each energy meter in Zoho IoT.
  3. Compute the total energy consumed by summing up all readings.



Image: Sample Custom Function code in deluge editor

Important: In the sample business logic for the implementation provided below, include your own custom values. 


// =============================

DpName = "Energy";

DpSource = "Energy Meter 1";

Period = "lastmonth";

// =============================

// Step 2: Define Zoho IoT API and ERP API endpoints

// =============================

// Zoho IoT API endpoint to fetch energy readings from the Zoho IoT application

iot_api_url = "https://app15414XXXX.zohoiot.in/iot/v1/datapoints/data?datapoint_name=" + DpName + "&source=" + DpSource + "&period=" + Period;

info iot_api_url;

// (Update to actual API endpoint in your Zoho IoT setup)

// ERP API endpoint to send consumption summary

erp_api_url = "https://erp.example.com/api/energy/monthly";

// Replace with actual ERP URL

// =============================

// Step 3: Fetch device list from IoT

// =============================

// Use Zoho Connection for authentication (example connection name: 'zoho_iot_conn')

device_response = invokeurl

[

url :iot_api_url

type :GET

connection:"iotconnection"

];

info device_response;

erp_url = "https://erp.example.com/receive_data";

device_response = invokeurl

[

url :erp_url

type :POST

connection:"erp_conn"

];

info device_response;



Conclusion

This implementation showcases how Zoho IoT’s Energy Monitoring solution can automate monthly energy data processing and integration with ERP systems. By leveraging secure connections and scheduled actions, the customer ensures accurate energy consumption data is shared seamlessly for billing and analysis reducing manual effort and improving operational efficiency.

See Also