Kaizen 105 Functions Integration Tasks and API Credits Part 1

Kaizen 105 Functions Integration Tasks and API Credits Part 1

Hello everyone!
Welcome back to another week of Kaizen!
In today's post, we will discuss functions, integration tasks, how they consume API and function credits.
In the next post, we will discuss connections, the difference between integration tasks and invoke URL in functions, how authentication happens for invoke URLs, and their credit consumption pattern.

What are functions in CRM?

A business involves multiple processes that cater to specific needs, like managing the sales pipeline, automating the flow of data between modules or different third-party systems, etc.
Zoho CRM gives you a wide range of options to achieve your business goals in the form of pre-defined functions under Setup > Developer Space > Functions. You can tweak these functions and associate them to workflows, blueprints, approval processes, circuits amongst many others, at just the click of a button.

While it is understandable that every business' needs are different, and the pre-defined functions, albeit very generic and most-commonly used, may not suit every business, Zoho CRM allows you to write your own functions specific to your needs.
More details on functions, here.
You can use Zoho's Deluge scripting language to write your own functions in a simple drag-and-drop function editor under Setup > Developer Space > Functions.

Integration tasks

We talked about how functions solve your business cases. How exactly do they do it?

Let's say you want to create a record in Zoho CRM using Functions. Instead of having to add values to every field the traditional way in web UI, functions have integration tasks that make working with records a lot easier as they act as API wrappers. These integration tasks help you make direct API calls without having to write code manually to handle API endpoints, HTTP methods, request parameters, or authentication mechanisms. What's more? They accept the input as function arguments in key-value pairs, much like JSON.

How are integration tasks beneficial to you?

When you use multiple Zoho products, data flow between them becomes much simpler and easier through integration tasks.
Your code becomes concise and easy to interpret.
As the integration tasks are essentially API wrappers, you do not have to worry about authorization as these integration tasks are considered as API calls triggered by the org's admin.

For today's post, let us discuss the function Converting a Sales Order to a Purchase Order, that uses integration tasks.
A gist of the code:
  1. Use the getRecordById integration tasks to get the ID of the Sales Order you want to convert to a Purchase Order
  2. Get the details of the product line items in the sales order, iterate through each of them, and add them to a map.
  3. Put these in another map to be used in the Purchase Order.
  4. Use the createRecord integration task and pass the new map to create a purchase order with the details from the sales order.

Here is the code:
Note that this function takes the soID(sales order ID) as the argument.

respMap = zoho.crm.getRecordById("Sales_Orders",input.soId.toLong());
productDet = ifnull(respMap.get("Product_Details"),"");
pdlist = List();
for each eachProd in productDet
{
productvalue = eachProd.get("product");
proid = productvalue.get("id");
proname = productvalue.get("name");
mp = Map();
mp.put("product",{"name":proname,"id":proid});
mp.put("quantity",ifnull(eachProd.get("quantity"),"0").toLong());
mp.put("list_price",ifnull(eachProd.get("list_price"),"0.0").toDecimal());
mp.put("discount",ifnull(eachProd.get("discount"),"0.0").toDecimal());
mp.put("total",ifnull(eachProd.get("total"),"0.0").toDecimal());
mp.put("net_total",ifnull(eachProd.get("net_total"),"0.0").toDecimal());
pdlist.add(mp);
}
paramap = Map();
paramap.put("Product_Details",pdlist);
paramap.put("Subject",ifnull(respMap.get("Subject"),""));
paramap.put("Contact_Name",ifnull(respMap.get("Contact_Name"),"").get("id"));
paramap.put("Account_Name",ifnull(respMap.get("Account_Name"),"").get("id"));
paramap.put("Owner",ifnull(respMap.get("Owner"),"").get("id"));
paramap.put("Sales_Order",ifnull(respMap.get("id"),""));
paramap.put("Terms_and_Conditions",ifnull(respMap.get("Terms_and_Conditions"),""));
paramap.put("Description",ifnull(respMap.get("Description"),""));
paramap.put("Adjustment",ifnull(respMap.get("Adjustment"),"0.0").toDecimal());
paramap.put("Discount",ifnull(respMap.get("Discount"),"0.0").toDecimal());
paramap.put("Tax",ifnull(respMap.get("Tax"),"0.0").toDecimal());
paramap.put("Shipping_Cuty",ifnull(respMap.get("Shipping_Cuty"),""));
paramap.put("Shipping_Code",ifnull(respMap.get("Shipping_Code"),""));
paramap.put("Shipping_Method",ifnull(respMap.get("Shipping_Method"),""));
paramap.put("Shipping_State",ifnull(respMap.get("Shipping_State"),""));
paramap.put("Shipping_Street",ifnull(respMap.get("Shipping_Street"),""));
paramap.put("Status",ifnull(respMap.get("Status"),""));
createResp = zoho.crm.createRecord("Purchase_Orders",paramap);
info paramap;
info createResp;


Here is the response:


This is the Purchase order created from the sales order.



I have associated this function to a workflow that converts a sales order to a purchase order, every time a sales order is created or updated.


How is authentication handled for integration tasks?

Functions with integration tasks are triggered by actions like workflows, blueprints etc. These triggers are org-wide and not restricted to specific sets of users. So, the integration tasks are executed as if the actions are done by the org’s admin.

API and Function Credits

Just like how APIs consume credits, integration tasks consume API credits, too.
The number of credits depends on the integration task you have used. For example, if you use the createRecord integration task, it consumes the same credits as the create records API. Similarly, the getRecordById integration task consumes the same credits as the Get Records API.
This is in addition to the function credits.
So, for the above function, the following are the various limits applied:
  • API credits - 2 - one each for getRecordById and createRecords integration tasks.
  • Function credits - 1

Where can you find the usage stats?


API Dashboard

Apart from API credit consumption, the API dashboard also gives you the details of the credits consumed by integration tasks.
The "Credits Usage" section shows you the credits specific to integration tasks. As you can see, out of the total available 56000 credits, 36 credits are consumed. Out of these 36 credits, 32 are from integration tasks.


The "Credits by Applications/Functions" pie chart gives you the credit consumption by each function or app.


When you click on one of them, you will see the details.


Functions Dashboard

The "Most Credits Consumed Functions" chart gives you the details of the functions that have consumed credits higher than most.


We hope you found this post useful. Next week, we will discuss Connections, invoke URLs and more.
Let us know what you think in the comments, or drop us an email at support@zohocrm.com.
Cheers!

      Zoho Developer Community







                                Zoho Desk Resources

                                • Desk Community Learning Series


                                • Digest


                                • Functions


                                • Meetups


                                • Kbase


                                • Resources


                                • Glossary


                                • Desk Marketplace


                                • MVP Corner


                                • Word of the Day



                                    Zoho Marketing Automation


                                            Manage your brands on social media



                                                  Zoho TeamInbox Resources

                                                    Zoho DataPrep Resources



                                                      Zoho CRM Plus Resources

                                                        Zoho Books Resources


                                                          Zoho Subscriptions Resources

                                                            Zoho Projects Resources


                                                              Zoho Sprints Resources


                                                                Qntrl Resources


                                                                  Zoho Creator Resources



                                                                    Zoho WorkDrive Resources



                                                                      Zoho Campaigns Resources


                                                                        Zoho CRM Resources

                                                                        • CRM Community Learning Series

                                                                          CRM Community Learning Series


                                                                        • Tips

                                                                          Tips

                                                                        • Functions

                                                                          Functions

                                                                        • Meetups

                                                                          Meetups

                                                                        • Kbase

                                                                          Kbase

                                                                        • Resources

                                                                          Resources

                                                                        • Digest

                                                                          Digest

                                                                        • CRM Marketplace

                                                                          CRM Marketplace

                                                                        • MVP Corner

                                                                          MVP Corner





                                                                            Design. Discuss. Deliver.

                                                                            Create visually engaging stories with Zoho Show.

                                                                            Get Started Now