Kaizen #61 - Composite API

Kaizen #61 - Composite API

Hello everyone!

Have you ever wanted to make different API calls in a single request? 
Save up on some API credits while still fulfilling your business case?
Reduce the round-trip time of a request?

We have got you!
The Composite API does it all!

What is a Composite API?

The Composite API allows you to combine up to five API requests in a single API call. You can also choose to execute all the APIs in a single database transaction, if required.

Before we look at this API in detail, let us get to know a few terms for better understanding.

  • Sub-requests - the individual API requests you use in a composite request.
  • Single database transaction - execution is considered complete only after all the sub-requests are executed. 
  • Round-trip time(RTT) - the time taken for the request to reach the server from the client and render a response in the client.
  • Rollback - when one of the sub-requests fails, the previous sub-requests that were executed will be reverted, and the composite API will be rolled back.
  • Concurrent execution - processing all the sub-requests at the same time, i.e, in parallel.
  • Index of the sub-requests - represents the order of execution. The execution begins at the 0th index.

How does the composite API reduce the round-trip time(RTT)?

Consider that you want to fetch the module metadata of leads, insert a contact, and fetch a quote. When you combine these calls in a composite request, the RTT is much lesser than the three individual requests from and to the client.

Concurrent and parallel execution

You can execute the sub-requests sequentially or in parallel, depending on your business needs.
The Boolean keys rollback_on_fail and concurrent_execution decide the execution flow of the composite API.
  • concurrent_execution - Represents whether you want to execute all the sub-requests in parallel. 
  • rollback_on_fail - Represents whether you want to rollback the entire composite request when one sub-request fails.

Note that these two keys cannot have the value "true" at the same time. That is, when the concurrent execution is true, a rollback cannot happen.

Let us discuss the two scenarios based on the values of these keys.
  1. Sub Requests are executed under the same transaction (rollback can be performed)
  2. Sub Requests are not executed under the same transaction

1. Sub-requests are executed under the same transaction (rollback can be performed)

  • When to use? 
    When there are dependent sub-requests and the execution of one depends on the response of another sub-request. Here, you must reference the sub-request whose data you want to use in another sub-request.
    For example, you want to upsert a record in the Contacts module(sub-request 1), upsert a record in the Accounts module(sub-request 2), and convert a lead while associating it to the previously upserted contact and account(sub-request 3). Sub-request 3 depends on the execution of sub-requests 1 and 2. This allows you to rollback the composite request when one of the sub-requests fails. That is, the contact and account will not be upserted. 
  • concurrent_execution - false
  • rollback_on_fail - true

Here is the JSON for the composite request:

{
    "rollback_on_fail": true,
    "concurrent_execution" : false,
    "__composite_requests": [
        {
            "sub_request_id":"1",
            "method":"POST",
            "uri":"/crm/v3/Contacts/upsert",
            "headers":{},
            "body":
            {
                "data":[
                    {
                        "Last_Name":"composite",
                        "Email":"composite@test.test"
                    }
                ]
            }
        },
        {
            "sub_request_id":"2",
            "method":"POST",
            "uri":"/crm/v3/Accounts/upsert",
            "body":{
                "data":[
                    {
                        "Account_Name":"C1",
                        "Email":"composite2@test.test"
                    }
                ]
            }
        },
        {
            "sub_request_id":"3",
            "method":"POST",
            "uri":"/crm/v3/Leads/111111000000095001/actions/convert",
            "body":{
                "data":[
                    {
                        "Accounts":"@{2:$.data[0].details.id}",
                        "Contacts":"@{1:$.data[0].details.id}"
                    }
                ]
            }
        }
    ]
}

2. Sub Requests are not executed under the same transaction 

a. concurrent execution is false
  • When to use? 
    When there are sub-requests that are internally dependent through an automation action.
    For example, you have configured a workflow that is triggered when the vendor's name is Zylker. In sub-request 1, you update an existing vendor's name from Zoho to Zylker. In sub-request 2, you create a contact associating the recently-updated vendor using its ID. Both appear like independent requests, but have internal dependency through the workflow. That is, to trigger the workflow, you must execute sub-request 1 first, followed by the second. Hence, you cannot use concurrent execution.
  • concurrent_execution - false
  • rollback_on_fail - false
{
    "concurrent_execution" : false,
    "__composite_requests": [
        {
            "sub_request_id":"1",
            "method":"PUT",
            "uri":"/crm/v3/Vendors/111111000000050313",
            "headers":{},
            "body":
            {
                "data":[
                    {
                        "Email":"v@gmail.com",
                        "Vendor_Name":"V1"
                    }
                ]
            }
        },
        {
            "sub_request_id":"2",
            "method":"POST",
            "uri":"/crm/v3/Contacts",
            "body":{
                "data":[
                    {
                        "Vendor_Name":"111111000000050313",
                        "Last_Name":"composite",
                        "Email":"composite2@test.test"
                    }
                ]
            }
        }
    ]
}

b. concurrent execution is true
Case 1: With independent sub-requests

  • When to use? 
    When your sub-requests are independent of each other and you want to save time by executing them in parallel. For example, fetching the leads, fetching the metadata of another module etc,.
  • concurrent_execution - true
  • rollback_on_fail - false

Case 2: With dependent and independent sub-requests

  • When to use? 
    When you have dependent and independent requests, and you want to execute independent requests in parallel to reduce execution time. For example, you want to create a lead(sub-request 1), create a contact referencing an account(sub-request 2) which will be created in another sub-request, and create an account(sub-request 3). Here, sub-requests 1 and 3 will be executed in parallel, and sub-request 2 will be executed after receiving the response from 3.
  • concurrent_execution - true
  • rollback_on_fail - false

Here is the sample input.

{
    "concurrent_execution" : true,
    "__composite_requests": [
        {
            "sub_request_id":"1",
            "method":"POST",
            "uri":"/crm/v3/Leads",
            "headers":{},
            "body":
            {
                "data":[
                    {
                        "Last_Name":"composite",
                        "Email":"composite@test.test"
                    }
                ]
            }
        },
        {
            "sub_request_id":"2",
            "method":"POST",
            "uri":"/crm/v3/Contacts",
            "body":{
                "data":[
                    {
                        "Account_Name":"@{1:$.data[0].details.id}",
                        "Last_Name":"composite",
                        "Email":"composite2@test.test"
                    }
                ]
            }
        },
        {
            "sub_request_id":"3",
            "method":"POST",
            "uri":"/crm/v3/Accounts",
            "body":{
                "data":[
                    {
                        "Account_Name":"A1"
                    }
                ]
            }
        }
    ]
}

Points to remember

  • rollback_on_fail and concurrent_execution keys cannot hold the value "true" at the same time.
  • You can only use a set of allowed APIs in the composite request. Refer to the Allowed APIs section on the help page.
  • When rollback_on_fail is true, the automation actions are executed only when all the sub-requests are served and a rollback is not performed. If one or more sub-requests fail and a rollback happens, the automation actions are not triggered.
  • Each composite API consumes one API credit, five concurrency credits, irrespective of the number of sub-requests.

How are responses and errors handled in the composite API

  • A composite API renders a success response when all the sub-requests are executed irrespective of their success or failure.
  • Every sub-request will have its corresponding error or success response, irrespective of the flow(concurrent or sequential).
  • You can get the details of the erroneous sub-request from the index in the response.

We hope you found this post useful. Let us know your thoughts in the comments.

Cheers!


    Access your files securely from anywhere

          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 Campaigns Resources


                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • 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


                                                                                  Zoho Show Resources


                                                                                    Zoho Writer Writer

                                                                                    Get Started. Write Away!

                                                                                    Writer is a powerful online word processor, designed for collaborative work.

                                                                                      Zoho CRM コンテンツ






                                                                                        Nederlandse Hulpbronnen


                                                                                            ご検討中の方





                                                                                                  • Recent Topics

                                                                                                  • VENDORS ARE NOT SYNCHED WITH CONTACTS IN CRM

                                                                                                    Hello, While the ACCOUNTS and CONTACTS (Including the primary contact) are synced with the CONTACTS module in CRM, the vendor's CONTACTS are not synced with CRM - which basically forces the users to re-enter all vendor's contacts twice and then update
                                                                                                  • Involved account types are not applicable when create journals

                                                                                                    { "journal_date": "2016-01-31", "reference_number": "20160131", "notes": "SimplePay Payroll", "line_items": [{ "account_id": "538624000000035003", "description": "Net Pay", "amount": 26690.09, "debit_or_credit": "credit" }, { "account_id": "538624000000000403", "description": "Gross", "amount": 32000, "debit_or_credit": "debit" }, { "account_id": "538624000000000427", "description": "CPP", "amount": 1295.64, "debit_or_credit": "debit" }, { "account_id": "538624000000000376", "description":
                                                                                                  • KB Templates

                                                                                                    * It would be nice if Zoho can provide users an option to create custom templates for KB articles. Also, it would be nice as well if the users can have an option to 1.) select a default template and 2.) declare default tag/tags, for KB articles created through Ticket's resolution.
                                                                                                  • Zoho CRM Reports Module on Mobil App

                                                                                                    I have the mobile app and the reports module doesn't appear in the sidebar for some reason. I saw a Youtube video where the user had the Reports module on mobile. Is there a setting to show it on mobile? Thanks.
                                                                                                  • Zoho Projects Android app update - List view enhancement

                                                                                                    Hello, everyone! In the latest android version(v3.9.15) of the Zoho Projects app update, we have enhanced the List view of tasks. We have also introduced a complete scroll of the tasks in the list view without scrolling the task fields(status, start date,
                                                                                                  • On the US Data Centre rather than the UK but dont know how to migrate it

                                                                                                    We have a new staff member with an external email address and cant add them to Zoho chat - we have been told its becuase we are in the UK but on a US Data centre - we therefore need to change it but no idea how to can anyone else as we are going round
                                                                                                  • Zoho Sheet Custom function column showing Error #EVAL!

                                                                                                    Hello I have a custom function in Zoho Sheet developed to convert a date time from one time zone to another. The custom function takes date and time columns and then using subHour( ) converts the time to PST time. However, though the custom function works,
                                                                                                  • Create Your Own Issue Management System

                                                                                                    Effective issue management is a cornerstone of project success. Every bug or issue, no matter how small, needs to be tracked and resolved in time to maintain project momentum. In this post, we’ll explore how an issue management system in Zoho Projects
                                                                                                  • Resource utlisation

                                                                                                    Dear Team, We use the excel for the weekly predicted people utilization how the resource are allocated , is there any way that i can use any of the zoho products.
                                                                                                  • Ask the experts - A live Q & A discussion on Zoho Recruit

                                                                                                    We are delighted to come back with another edition of Ask the Experts community series. This edition, we'll be focusing on everything about Zoho Recruit. The topics will focus on the features that are used/asked by the majority of users and also based
                                                                                                  • Bug - OTP (email) and No Duplicates

                                                                                                    Scenario: Form with an email field, Validation: "No Duplicates" (because I want to ensure 1 entry per email). Embedded form into website (JS option). Enabled email based OTP. 1st test (via my website) - entered my email address - sent OTP - entered pin,
                                                                                                  • Personal Facebook page posting instead of Business Page

                                                                                                    I have a Facebook page that is associated with my Personal Profile and I am the Admin of that Page. I would like to schedule and Post to my Personal Page not the Business Page. Each time I try to connect to the "Page" it takes me to the Business Page. Is there a way of connecting to my personal page?
                                                                                                  • Recording depreciation of fixed assets as a percentage of residual value

                                                                                                    In India, fixed assets are depreciated as a percentage of their residual value at the beginning of each fiscal year. I went through the documentation for creating recurring journal entries, but could only find ways to depreciate by a fixed rupee amount
                                                                                                  • Function #28: Automatically calculate Customer Loyalty points

                                                                                                    Hello everyone, and welcome back to our series! Today, we're excited to share a workflow designed to streamline the management of loyalty points. Many businesses offer incentives or rewards in the form of loyalty points to their customers as a way to
                                                                                                  • Function #6: Calculate Commissions for paid invoices

                                                                                                    Zoho Books helps you automate the process of calculating and recording commissions paid to sales persons using custom functions. We've written a script that computes the commission amount based on the percentage of commission you enter and creates an
                                                                                                  • How to Add Product SKU in Invoice?

                                                                                                    How to Add Product SKU in Invoice?
                                                                                                  • Tracking movement between departments

                                                                                                    I've been developing a reporting system in Zoho and one of the groups I want to develop a report on primarily moves tickets from department to another. Is there a way to set up the reporting on Zoho (or Zoho Reports) that can tell me the number of tickets
                                                                                                  • Zoho CRM Calendar View

                                                                                                    Hello Zoho team, We need desperately a calendar view next to list, kandan and other views. I think it should be easy to implement as you already have the logic from Projects and also from Kanban View in CRM. In calendar view when we set it up - we choose
                                                                                                  • Call transcrition working for ringcentral?

                                                                                                    I don't see anything about what telephony providers can be used. The Zoho support person A said that RingCentral isn't supported. Zoho support person B said that it works, just make sure the call recording link works. Excellent instructions here: Call
                                                                                                  • What is syntax to call creator function (or trigger a creator workflow) from CRM deluge?

                                                                                                    What is syntax to call creator function (or trigger a creator workflow) from CRM deluge?
                                                                                                  • WhatsApp and Zoho Creator Integration

                                                                                                    How we have integrate WhatsApp App with Zoho Creator without using external application ?
                                                                                                  • Improve Creator Calendar Report

                                                                                                    Please can you improve the Creator Calendar Report General There is no way to highlight certain days, for example weekends or public holidays. There is no way to hide certain days, for example weekends. There is no way to modify the day header, it just
                                                                                                  • Important updates to Zoho CRM's email deliverability

                                                                                                    Last modified on: Jul 24, 2024 These enhancements are released for all users across all data centers. Modified on: Oct 30, 2023 Organisations that are in the Enterprise and above editions of Zoho CRM, and have not authenticated their email-sending domains
                                                                                                  • Custom modules not showing in developer console

                                                                                                    I'm trying to create a custom summing function for a custom module I made in my CRM. When I go to create the function, my module isnt showing up. Do I need to share the custom moldule with my developer console or something of the like?
                                                                                                  • Meetups Gratuitos Junio 2024 - Profundiza en las funcionalidades de tu Zoho CRM

                                                                                                    Este junio, aprende a sacar el máximo provecho de tu Zoho CRM en la segunda edición de los Zoho Meetups 2024. Los días 18 a 21 de junio, Zoho organiza los Meetups gratuitos para usuarios de Zoho CRM en Valencia, Barcelona, Madrid y Sevilla, donde expertos
                                                                                                  • How to get the Dashboard page to be the first page when you open the app

                                                                                                    So when it opens on a tablet or phone it opens on the welcome page, thanks.
                                                                                                  • Integration between Zoho CRM and Zoho WorkDrive

                                                                                                    I'd like to search Zoho for an invoice I've added as an attachment (pdf) to an account. The name of the invoice is 1388-advertiserx-July.pdf - but I can't find it using the search function for any of these terms: 1388 1388-advertiserx 1388-advertiserx-July.pdf
                                                                                                  • Tip #17: How to mandate partial payment for your appointments

                                                                                                    When you require partial payments during the booking process, customers can only schedule with you after paying a certain amount in advance. This deposit acts as a commitment between both parties. Apart from that, it has many more advantages. Benefits
                                                                                                  • Why option for 'include form submission in the body of the email' check box is missing

                                                                                                    Hi In all our forms we have configured an <Email Notification> (<Rules> <Form Rules>) In some forms, there is an option to <include form submission in the body of the email> in the <Additional Options> section, however, this option is not available in
                                                                                                  • Mozilla Vault extension will not Unlock even once.

                                                                                                    I have been using the Vault extension in Chrome based browsers for years, yet after installing the Mozilla Extension in Firefox, it will not unlock. Initially it did redirect me to log into my account, and then enter the master password. However, it did
                                                                                                  • Unable to Download CRM Contact Data: WorkDrive Integration Issues

                                                                                                    ## Problem Description We need to let users download contact information from CRM as CSV files to their local computers. Since we couldn't implement a direct download option, we're trying to use WorkDrive as a workaround - but we're encountering issues
                                                                                                  • Sort mail by name and subject

                                                                                                    I don't see sort function on columns FROM and Subject. I see only sort functio by date. Could add it ?
                                                                                                  • Zoho Creator monthly roundup - September 2024

                                                                                                    Hello all, We're back with an exciting set of new features and enhancements that will elevate your Creator experience even further. In case you missed it, we’ve recently revamped our Product Roadmap page, now with a refreshed design and showcasing all
                                                                                                  • Kiosk Studio Session #1: View paid customers in the same industry

                                                                                                    Update | 15 Oct 2024: Session #2 is now available here! Hello everyone! We're excited to launch our new series of posts on Kiosk Studio today. Called Kiosk Studio Sessions , these posts will be packed with actionable ideas to help you get the most out
                                                                                                  • Issues hosting Zoho Desk Web Form on SharePoint and/or Power BI

                                                                                                    Zoho Desk onboarding support has no experience with embedding their web form in either SharePoint or Power BI. Microsoft states that SharePoint and Power BI only support iframe HTML. And unfortunately, the web form embed code that Zoho generates is not
                                                                                                  • "Send with Zoho Sign" broken

                                                                                                    Our company uses hyphens in our file name conventions. Our users have been sending the files from other modules with the "Send with Zoho Sign" shortcut in the upper right buttons. Since around June 10, 2024, this stopped working. Our users can send the
                                                                                                  • Not able to change colors help center

                                                                                                    Hi. How can I change the orange color in the help center? You can change everything besides this font color And how can I remove the part on the bottom?
                                                                                                  • Transform Numeric Values using st, nd, rd, th or Convert Numerals to Ordinal Form - Deluge

                                                                                                    Please Use this sample Code This_Day_Date = zoho.currentdate.toString("dd"); value1 = "th"; if(This_Day_Date.right(1) ="1" && This_Day_Date != "11") { This_Day_Date = This_Day_Date+" "+"st"; } else if ( This_Day_Date.right(1) = "2" && This_Day_Date !=
                                                                                                  • Kaizen #166 - Handling Query Variables in Zoho CRM

                                                                                                    Hello, Code Enthusiasts! Welcome to another week of Kaizen! This week, we'll dive into handling variables in Zoho CRM Queries and see how they can be deployed in Kiosk to dynamically retrieve data. This technique is especially useful for integrating data
                                                                                                  • Automate User Invitations on Zoho Desk with API

                                                                                                    Automate User Invitations on Zoho Desk with API Hello Team, We are excited to announce that you can now automatically invite users to the Zoho Desk portal using the API! ### How It Works For example, when a contact is created in Zoho Desk and you enable
                                                                                                  • Next Page